Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6b37025

Browse files
committed
Some more changes for the tests
1 parent b45439f commit 6b37025

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

Source/ORTS.Common/ConsistGenerator.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,18 @@ public static Stream GetConsist(string requestedPath)
9393
{
9494
GltfVisualTestRun = true;
9595

96+
var mm = Path.GetFileNameWithoutExtension(requestedPath).Split('&').ElementAtOrDefault(1);
97+
var nn = int.TryParse(Path.GetFileNameWithoutExtension(requestedPath).Split('#').ElementAtOrDefault(1), out var requestedModelNumberrrr);
98+
var mmm = Directory.EnumerateFileSystemEntries(baseDir, "*.*", SearchOption.AllDirectories)
99+
.Where(f => !f.Contains(Path.Combine(baseDir, "2.0")) && (f.EndsWith(".gltf") || f.EndsWith(".glb")))
100+
.Select(f => Path.GetFileNameWithoutExtension(f))
101+
.Concat(Directory.EnumerateDirectories(Path.Combine(baseDir, "2.0")));
102+
96103
var models = Directory.EnumerateFileSystemEntries(baseDir, "*.*", SearchOption.AllDirectories)
97104
.Where(f => !f.Contains(Path.Combine(baseDir, "2.0")) && (f.EndsWith(".gltf") || f.EndsWith(".glb")))
98105
.Select(f => Path.GetFileNameWithoutExtension(f))
99106
.Concat(Directory.EnumerateDirectories(Path.Combine(baseDir, "2.0")))
100-
.Where((m, n) => m == (Path.GetFileNameWithoutExtension(requestedPath).Split('&').ElementAtOrDefault(1) ?? m) &&
107+
.Where((m, n) => Path.GetFileName(m) == (Path.GetFileNameWithoutExtension(requestedPath).Split('&').ElementAtOrDefault(1) ?? Path.GetFileName(m)) &&
101108
n == (int.TryParse(Path.GetFileNameWithoutExtension(requestedPath).Split('#').ElementAtOrDefault(1), out var requestedModelNumber) ? requestedModelNumber : n));
102109

103110
var uid = 0;

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,13 +2688,11 @@ protected virtual void UpdateHornAndBell(float elapsedClockSeconds)
26882688
{
26892689
SignalEvent(Event.BellOn);
26902690
if (Train.TrainType != Train.TRAINTYPE.REMOTE && MPManager.IsMultiPlayer()) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 1)).ToString());
2691-
if (ConsistGenerator.GltfVisualTestRun) Train.SignalEvent(Event.BellOn);
26922691
}
26932692
else if (!Bell && PreviousBell)
26942693
{
26952694
SignalEvent(Event.BellOff);
26962695
if (Train.TrainType != Train.TRAINTYPE.REMOTE && MPManager.IsMultiPlayer()) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 0)).ToString());
2697-
if (ConsistGenerator.GltfVisualTestRun) Train.SignalEvent(Event.BellOff);
26982696
}
26992697

27002698
PreviousHorn = Horn;
@@ -4990,6 +4988,10 @@ public override void SignalEvent(Event evt)
49904988
}
49914989
break;
49924990
}
4991+
case Event.GenericItem1On: if (ConsistGenerator.GltfVisualTestRun) GenericItem1 = true; break;
4992+
case Event.GenericItem1Off: if (ConsistGenerator.GltfVisualTestRun) GenericItem1 = false; break;
4993+
case Event.GenericItem2On: if (ConsistGenerator.GltfVisualTestRun) GenericItem2 = true; break;
4994+
case Event.GenericItem2Off: if (ConsistGenerator.GltfVisualTestRun) GenericItem2 = false; break;
49934995
}
49944996

49954997
base.SignalEvent(evt);

Source/RunActivity/Viewer3D/GltfShape.cs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public class GltfShape : SharedShape
5454
int SkeletonRootNode;
5555
public bool MsfsFlavoured;
5656

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;
6161

6262
/// <summary>
6363
/// glTF specification declares that the model's forward is +Z. However OpenRails uses -Z as forward,
@@ -338,7 +338,7 @@ public class GltfDistanceLevel : DistanceLevel
338338
internal readonly GltfShape Shape;
339339

340340
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" };
342342

343343
public GltfDistanceLevel(GltfShape shape, int lodId, Gltf gltfFile, string gltfFileName)
344344
{
@@ -455,10 +455,10 @@ public GltfDistanceLevel(GltfShape shape, int lodId, Gltf gltfFile, string gltfF
455455
if (lodId == 0)
456456
{
457457
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();
462462

463463
if (SubObjects.FirstOrDefault() is GltfSubObject gltfSubObject)
464464
{
@@ -561,11 +561,10 @@ public GltfDistanceLevel(GltfShape shape, int lodId, Gltf gltfFile, string gltfF
561561

562562
if (ConsistGenerator.GltfVisualTestRun)
563563
{
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,
565565
// because these are the ones capable of playing a loop.
566566
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];
569568
}
570569
}
571570
}
@@ -1702,7 +1701,7 @@ public override int GetAnimationParent(int animationNumber)
17021701
public override Matrix GetMatrixProduct(int iNode) => base.GetMatrixProduct(iNode) * PlusZToForward;
17031702
public override bool IsAnimationArticulation(int number) => GltfAnimations?.ElementAtOrDefault(number)?.Channels?.FirstOrDefault()?.TimeArray == null;
17041703
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;
17061705

17071706
public bool HasAnimation(int number) => GltfAnimations?.ElementAtOrDefault(number)?.Channels?.FirstOrDefault() != null;
17081707
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)
17141713
/// <param name="time">Actual time in the animation clip in seconds.</param>
17151714
public void Animate(int animationNumber, float time, Matrix[] animatedMatrices)
17161715
{
1717-
if (!EnableAnimations)
1716+
if (!EnableAnimations && !ConsistGenerator.GltfVisualTestRun)
17181717
return;
17191718

17201719
foreach (var channel in GltfAnimations[animationNumber].Channels)
@@ -1740,31 +1739,27 @@ public void Animate(int animationNumber, float time, Matrix[] animatedMatrices)
17401739
case AnimationSampler.InterpolationEnum.STEP: amount = 0; break;
17411740
default: amount = 0; break;
17421741
}
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];
17471742
switch (channel.Path)
17481743
{
17491744
case AnimationChannelTarget.PathEnum.translation:
1750-
translation = channel.Interpolation == AnimationSampler.InterpolationEnum.CUBICSPLINE
1745+
Translations[channel.TargetNode] = channel.Interpolation == AnimationSampler.InterpolationEnum.CUBICSPLINE
17511746
? Vector3.Hermite(channel.OutputVector3[Property(frame1)], channel.OutputVector3[OutTangent(frame2)], channel.OutputVector3[Property(frame2)], channel.OutputVector3[InTangent(frame2)], amount)
17521747
: Vector3.Lerp(channel.OutputVector3[frame1], channel.OutputVector3[frame2], amount);
17531748
break;
17541749
case AnimationChannelTarget.PathEnum.rotation:
1755-
rotation = channel.Interpolation == AnimationSampler.InterpolationEnum.CUBICSPLINE
1750+
Rotations[channel.TargetNode] = channel.Interpolation == AnimationSampler.InterpolationEnum.CUBICSPLINE
17561751
? CsInterp(channel.OutputQuaternion[Property(frame1)], channel.OutputQuaternion[OutTangent(frame2)], channel.OutputQuaternion[Property(frame2)], channel.OutputQuaternion[InTangent(frame2)], amount)
17571752
: Quaternion.Slerp(channel.OutputQuaternion[frame1], channel.OutputQuaternion[frame2], amount);
17581753
break;
17591754
case AnimationChannelTarget.PathEnum.scale:
1760-
scale = channel.Interpolation == AnimationSampler.InterpolationEnum.CUBICSPLINE
1755+
Scales[channel.TargetNode] = channel.Interpolation == AnimationSampler.InterpolationEnum.CUBICSPLINE
17611756
? Vector3.Hermite(channel.OutputVector3[Property(frame1)], channel.OutputVector3[OutTangent(frame2)], channel.OutputVector3[Property(frame2)], channel.OutputVector3[InTangent(frame2)], amount)
17621757
: Vector3.Lerp(channel.OutputVector3[frame1], channel.OutputVector3[frame2], amount);
17631758
break;
17641759
case AnimationChannelTarget.PathEnum.weights:
17651760
default: break;
17661761
}
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]);
17681763
}
17691764
}
17701765

@@ -1840,13 +1835,13 @@ public void Animate(int animationNumber, float time, Matrix[] animatedMatrices)
18401835
{ "SheenChair".ToLower(), Matrix.CreateScale(2) },
18411836
{ "SheenCloth".ToLower(), Matrix.CreateScale(50) },
18421837
{ "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) },
18441839
{ "StainedGlassLamp".ToLower(), Matrix.CreateScale(3) },
18451840
{ "Suzanne".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
18461841
{ "TextureCoordinateTest".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
18471842
{ "TextureEncodingTest".ToLower(), Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(0, 3, 0) },
18481843
{ "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) },
18501845
{ "TextureTransformMultiTest".ToLower(), Matrix.CreateScale(2) * Matrix.CreateTranslation(0, 4, 0) },
18511846
{ "TextureTransformTest".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
18521847
{ "ToyCar".ToLower(), Matrix.CreateScale(80) * Matrix.CreateTranslation(0, 2, 0)},

0 commit comments

Comments
 (0)