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

Skip to content

Commit b45439f

Browse files
committed
Adjustments for the visual tests
1 parent 9e2fad4 commit b45439f

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

Source/ORTS.Common/ConsistGenerator.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ namespace ORTS.Common
2929
/// </summary>
3030
public class ConsistGenerator
3131
{
32-
public static bool GeneratedRun;
32+
/// <summary>
33+
/// Indicates if the current run is a glTF visual test only. It is possible to generate an on-the-fly consist of all the Khronos test models.
34+
/// </summary>
35+
public static bool GltfVisualTestRun;
3336

3437
const string ConsistTemplateStart = @"Train (
3538
TrainCfg ( ""trainname""
@@ -84,12 +87,12 @@ public static Stream GetConsist(string requestedPath)
8487
var keyword = RequestedType(requestedPath);
8588
Debug.Assert(keyword != null);
8689

87-
GeneratedRun = true;
88-
8990
var consist = ConsistTemplateStart.Replace("trainname", keyword);
9091

9192
if (keyword.StartsWith("glTF"))
9293
{
94+
GltfVisualTestRun = true;
95+
9396
var models = Directory.EnumerateFileSystemEntries(baseDir, "*.*", SearchOption.AllDirectories)
9497
.Where(f => !f.Contains(Path.Combine(baseDir, "2.0")) && (f.EndsWith(".gltf") || f.EndsWith(".glb")))
9598
.Select(f => Path.GetFileNameWithoutExtension(f))

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,11 +2688,13 @@ 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);
26912692
}
26922693
else if (!Bell && PreviousBell)
26932694
{
26942695
SignalEvent(Event.BellOff);
26952696
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);
26962698
}
26972699

26982700
PreviousHorn = Horn;
@@ -4835,6 +4837,7 @@ public void ToggleCabRadio( bool newState)
48354837
public void ToggleWipers(bool newState)
48364838
{
48374839
SignalEvent(newState ? Event.WiperOn : Event.WiperOff);
4840+
if (ConsistGenerator.GltfVisualTestRun) Train.SignalEvent(newState ? Event.WiperOn : Event.WiperOff);
48384841
}
48394842

48404843
public void SetBailOff(bool bailOff)
@@ -4902,12 +4905,14 @@ public void GenericItem1Toggle()
49024905
{
49034906
GenericItem1 = !GenericItem1;
49044907
SignalEvent(GenericItem1? Event.GenericItem1On : Event.GenericItem1Off); // hook for sound trigger
4908+
if (ConsistGenerator.GltfVisualTestRun) Train.SignalEvent(GenericItem1 ? Event.GenericItem1On : Event.GenericItem1Off);
49054909
}
49064910

49074911
public void GenericItem2Toggle()
49084912
{
49094913
GenericItem2 = !GenericItem2;
49104914
SignalEvent(GenericItem2 ? Event.GenericItem2On : Event.GenericItem2Off); // hook for sound trigger
4915+
if (ConsistGenerator.GltfVisualTestRun) Train.SignalEvent(GenericItem2 ? Event.GenericItem2On : Event.GenericItem2Off);
49114916
}
49124917

49134918
public override bool GetCabFlipped()

Source/RunActivity/Viewer3D/GltfShape.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public override Matrix SetRenderMatrices(ShapePrimitive baseShapePrimitive, Matr
177177
Matrix.Multiply(ref bones[j], ref PlusZToForward, out bones[j]);
178178

179179
// The ConsistGenerator is used to show all the Khronos sample models for testing purposes. However they need adjustments to show them all at once.
180-
if (ConsistGenerator.GeneratedRun && SampleModelsAdjustments.TryGetValue(Path.GetFileNameWithoutExtension(FilePath), out var adjustment))
180+
if (ConsistGenerator.GltfVisualTestRun && SampleModelsAdjustments.TryGetValue(Path.GetFileNameWithoutExtension(FilePath), out var adjustment))
181181
Matrix.Multiply(ref bones[j], ref adjustment, out bones[j]);
182182

183183
Matrix.Multiply(ref bones[j], ref tileTranslation, out bones[j]);
@@ -338,6 +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" };
341342

342343
public GltfDistanceLevel(GltfShape shape, int lodId, Gltf gltfFile, string gltfFileName)
343344
{
@@ -487,7 +488,7 @@ public GltfDistanceLevel(GltfShape shape, int lodId, Gltf gltfFile, string gltfF
487488
// Use MatrixNames for storing animation and articulation names.
488489
// Here the MatrixNames are not bound to nodes (and matrices), but rather to the animation number.
489490
shape.MatrixNames[j] = gltfAnimation.Name ?? "";
490-
var animation = new GltfAnimation(gltfAnimation.Name);
491+
var animation = new GltfAnimation(shape.MatrixNames[j]);
491492

492493
for (var k = 0; k < gltfAnimation.Channels.Length; k++)
493494
{
@@ -558,7 +559,14 @@ public GltfDistanceLevel(GltfShape shape, int lodId, Gltf gltfFile, string gltfF
558559
}
559560
}
560561

561-
//if (shape.GltfAnimations.Count > 0) { shape.GltfAnimations.Add(shape.GltfAnimations[0]); shape.MatrixNames[shape.GltfAnimations.Count - 1] = "ORTSITEM1CONTINUOUS"; }
562+
if (ConsistGenerator.GltfVisualTestRun)
563+
{
564+
// Assign the first four animations to Wipers [V], Bell [Shift+B], Item1Continuous [Shift+,], Item2Continuous [Shift+.] respectively,
565+
// because these are the ones capable of playing a loop.
566+
for (var i = 0; i < shape.GltfAnimations.Count; i++)
567+
if (i < TestControls.Length)
568+
shape.MatrixNames[i] = TestControls[i];
569+
}
562570
}
563571
}
564572

@@ -1784,6 +1792,7 @@ public void Animate(int animationNumber, float time, Matrix[] animatedMatrices)
17841792
{ "AnimatedCube".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
17851793
{ "AnimatedMorphCube".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
17861794
{ "AnimatedMorphSphere".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1795+
{ "AnimatedTriangle".ToLower(), Matrix.CreateTranslation(0, 1, 0) },
17871796
{ "AntiqueCamera".ToLower(), Matrix.CreateScale(0.5f) },
17881797
{ "AttenuationTest".ToLower(), Matrix.CreateScale(0.3f) * Matrix.CreateTranslation(0, 4, 0) },
17891798
{ "Avocado".ToLower(), Matrix.CreateScale(50) },
@@ -1826,16 +1835,27 @@ public void Animate(int animationNumber, float time, Matrix[] animatedMatrices)
18261835
{ "OrientationTest".ToLower(), Matrix.CreateScale(0.2f) * Matrix.CreateTranslation(0, 2, 0) },
18271836
{ "ReciprocatingSaw".ToLower(), Matrix.CreateScale(0.02f) * Matrix.CreateTranslation(0, 3, 0) },
18281837
{ "RecursiveSkeletons".ToLower(), Matrix.CreateScale(0.05f) },
1829-
{ "RiggedSimple".ToLower(), Matrix.CreateTranslation(0, 8, 0) },
1838+
{ "RiggedSimple".ToLower(), Matrix.CreateTranslation(0, 5, 0) },
18301839
{ "SciFiHelmet".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
18311840
{ "SheenChair".ToLower(), Matrix.CreateScale(2) },
1832-
{ "SheenCloth".ToLower(), Matrix.CreateScale(20) },
1833-
{ "SpecGlossVsMetalRough".ToLower(), Matrix.CreateScale(5) },
1834-
{ "SpecularTest".ToLower(), Matrix.CreateScale(3) },
1841+
{ "SheenCloth".ToLower(), Matrix.CreateScale(50) },
1842+
{ "SpecGlossVsMetalRough".ToLower(), Matrix.CreateScale(7) * Matrix.CreateTranslation(0, 2, 0) },
1843+
{ "SpecularTest".ToLower(), Matrix.CreateScale(3) * Matrix.CreateTranslation(0, 2, 0) },
18351844
{ "StainedGlassLamp".ToLower(), Matrix.CreateScale(3) },
18361845
{ "Suzanne".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
18371846
{ "TextureCoordinateTest".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1838-
{ "TextureEncodingTest".ToLower(), Matrix.CreateTranslation(0, 6, 0) },
1847+
{ "TextureEncodingTest".ToLower(), Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(0, 3, 0) },
1848+
{ "TextureLinearInterpolationTest".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1849+
{ "TextureSettingsTest".ToLower(), Matrix.CreateTranslation(0, 6, 0) },
1850+
{ "TextureTransformMultiTest".ToLower(), Matrix.CreateScale(2) * Matrix.CreateTranslation(0, 4, 0) },
1851+
{ "TextureTransformTest".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1852+
{ "ToyCar".ToLower(), Matrix.CreateScale(80) * Matrix.CreateTranslation(0, 2, 0)},
1853+
{ "TransmissionRoughnessTest".ToLower(), Matrix.CreateScale(5) * Matrix.CreateTranslation(0, 3, 0) },
1854+
{ "TransmissionTest".ToLower(), Matrix.CreateScale(3) * Matrix.CreateTranslation(0, 2, 0) },
1855+
{ "TwoSidedPlane".ToLower(), Matrix.CreateTranslation(0, 1, 0) },
1856+
{ "UnlitTest".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1857+
{ "VertexColorTest".ToLower(), Matrix.CreateScale(2) * Matrix.CreateTranslation(0, 2, 0) },
1858+
{ "WaterBottle".ToLower(), Matrix.CreateScale(7) * Matrix.CreateTranslation(0, 2, 0) },
18391859
};
18401860
}
18411861

Source/RunActivity/Viewer3D/RollingStock/MSTSWagonViewer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ void MatchMatrixToPart(MSTSWagon car, int matrix, int bogieMatrix)
574574
}
575575
else
576576
{
577-
if (matrixAnimated && matrix != 0)
577+
if (matrixAnimated && matrix != 0 && !ConsistGenerator.GltfVisualTestRun)
578578
RunningGear.AddMatrix(matrix);
579579

580580
for (var i = 0; i < TrainCarShape.SharedShape.GetAnimationNamesCount(); i++)

0 commit comments

Comments
 (0)