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

Skip to content

Commit 23ac480

Browse files
committed
Easier glTF testing of the sample models by procedurally generating the con-s and eng-s
1 parent 93a3f27 commit 23ac480

File tree

5 files changed

+84
-5
lines changed

5 files changed

+84
-5
lines changed

Source/Orts.Formats.Msts/ConsistFile.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ public ConsistFile(string filePath)
3939
Name = Train.TrainCfg.Name;
4040
}
4141

42+
/// <summary>
43+
/// Allows to use a procedurally generated consist file.
44+
/// </summary>
45+
public ConsistFile(Stream inputStream, string filePath)
46+
{
47+
using (var stf = new STFReader(inputStream, filePath, System.Text.Encoding.UTF8, false))
48+
stf.ParseFile(new STFReader.TokenProcessor[] {
49+
new STFReader.TokenProcessor("train", ()=>{ Train = new Train_Config(stf); }),
50+
});
51+
}
52+
4253
public override string ToString()
4354
{
4455
return Name;

Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ public virtual void LoadFromWagFile(string wagFilePath)
398398
if (File.Exists(orFile))
399399
wagFilePath = orFile;
400400

401-
using (STFReader stf = new STFReader(wagFilePath, true))
401+
using (STFReader stf = ConsistGenerator.IsWagonRecognized(wagFilePath)
402+
? new STFReader(ConsistGenerator.GetWagon(wagFilePath), wagFilePath, System.Text.Encoding.UTF8, true)
403+
: new STFReader(wagFilePath, true))
402404
{
403405
while (!stf.Eof)
404406
{

Source/Orts.Simulation/Simulation/RollingStocks/RollingStock.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Orts.Parsers.Msts;
2020
using Orts.Simulation.Physics;
2121
using Orts.Simulation.RollingStocks.SubSystems;
22+
using ORTS.Common;
2223
using System;
2324
using System.Collections.Generic;
2425
using System.Diagnostics;
@@ -138,7 +139,9 @@ public GenericWAGFile(string filenamewithpath)
138139

139140
public void WagFile(string filenamewithpath)
140141
{
141-
using (STFReader stf = new STFReader(filenamewithpath, false))
142+
using (STFReader stf = ConsistGenerator.IsWagonRecognized(filenamewithpath)
143+
? new STFReader(ConsistGenerator.GetWagon(filenamewithpath), filenamewithpath, System.Text.Encoding.UTF8, false)
144+
: new STFReader(filenamewithpath, false))
142145
stf.ParseBlock(new STFReader.TokenProcessor[] {
143146
new STFReader.TokenProcessor("engine", ()=>{ Engine = new EngineClass(stf); }),
144147
new STFReader.TokenProcessor("_openrails", ()=>{ OpenRails = new OpenRailsData(stf); }),

Source/Orts.Simulation/Simulation/Simulator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ private Train InitializePlayerTrain()
12521252
// place rear of train on starting location of aiPath.
12531253
train.RearTDBTraveller = new Traveller(TSectionDat, TDB.TrackDB.TrackNodes, aiPath);
12541254

1255-
ConsistFile conFile = new ConsistFile(conFileName);
1255+
ConsistFile conFile = ConsistGenerator.IsConsistRecognized(conFileName) ? new ConsistFile(ConsistGenerator.GetConsist(conFileName), conFileName) : new ConsistFile(conFileName);
12561256
CurveDurability = conFile.Train.TrainCfg.Durability; // Finds curve durability of consist based upon the value in consist file
12571257
train.TcsParametersFileName = conFile.Train.TrainCfg.TcsParametersFileName;
12581258

@@ -1269,7 +1269,7 @@ private Train InitializePlayerTrain()
12691269
wagonFilePath = wagonFolder + @"\" + wagon.Name + ".eot";
12701270
}
12711271

1272-
if (!File.Exists(wagonFilePath))
1272+
if (!File.Exists(wagonFilePath) && !ConsistGenerator.IsWagonRecognized(wagonFilePath))
12731273
{
12741274
// First wagon is the player's loco and required, so issue a fatal error message
12751275
if (wagon == conFile.Train.TrainCfg.WagonList[0])

Source/RunActivity/Viewer3D/GltfShape.cs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using Orts.Viewer3D.Processes;
3131
using ORTS.Common;
3232
using glTFLoader.Schema;
33+
using Orts.Simulation.AIs;
3334

3435
namespace Orts.Viewer3D
3536
{
@@ -168,6 +169,11 @@ public override Matrix SetRenderMatrices(ShapePrimitive baseShapePrimitive, Matr
168169
hi = shapePrimitive.Hierarchy[hi];
169170
}
170171
Matrix.Multiply(ref bones[j], ref PlusZToForward, out bones[j]);
172+
173+
// The ConsistGenerator is used to show all the Khronos sample models for testing purposes. However they need adjustments to show them all at once.
174+
if (ConsistGenerator.GeneratedRun && SampleModelsAdjustments.TryGetValue(Path.GetFileNameWithoutExtension(FilePath), out var adjustment))
175+
Matrix.Multiply(ref bones[j], ref adjustment, out bones[j]);
176+
171177
Matrix.Multiply(ref bones[j], ref tileTranslation, out bones[j]);
172178
}
173179

@@ -525,7 +531,7 @@ public GltfDistanceLevel(GltfShape shape, int lodId, Gltf gltfFile, string gltfF
525531
}
526532
}
527533

528-
if (shape.GltfAnimations.Count > 0) { shape.GltfAnimations.Add(shape.GltfAnimations[0]); shape.MatrixNames[shape.GltfAnimations.Count - 1] = "ORTSITEM1CONTINUOUS"; }
534+
//if (shape.GltfAnimations.Count > 0) { shape.GltfAnimations.Add(shape.GltfAnimations[0]); shape.MatrixNames[shape.GltfAnimations.Count - 1] = "ORTSITEM1CONTINUOUS"; }
529535
}
530536
}
531537

@@ -1781,6 +1787,63 @@ public void Animate(int animationNumber, float time, Matrix[] animatedMatrices)
17811787
static readonly Func<float, float> D = (t) => t*t*t - t*t;
17821788
static readonly Func<Quaternion, Quaternion, Quaternion, Quaternion, float, Quaternion> CsInterp = (v1, b1, v2, a2, t) =>
17831789
Quaternion.Normalize(Quaternion.Multiply(v1, A(t)) + Quaternion.Multiply(b1, B(t)) + Quaternion.Multiply(v2, C(t)) + Quaternion.Multiply(a2, D(t)));
1790+
1791+
/// <summary>
1792+
/// It is used to store the adjustments needed for the Khronos sample models for being able to show them all at once in a single consist.
1793+
/// For this to work 'git clone https://github.com/KhronosGroup/glTF-Sample-Models.git' to the MSTS/TRAINS/TRAINSET folder, so that the
1794+
/// models will be available in e.g. MSTS/TRAINS/TRAINSET/glTF-Sample-Models/2.0/... folder. Then start like:
1795+
/// RunActivity.exe -start -explorer "C:\Devel\MSTS\ROUTES\USA2\PATHS\tut6path.pat" "glTF-Sample-Models" 12:00 1 0
1796+
/// </summary>
1797+
static readonly Dictionary<string, Matrix> SampleModelsAdjustments = new Dictionary<string, Matrix>
1798+
{
1799+
{ "2CylinderEngine".ToLower(), Matrix.CreateScale(0.01f) * Matrix.CreateTranslation(0, 2, 0) },
1800+
{ "ABeautifulGame".ToLower(), Matrix.CreateScale(10) },
1801+
{ "AnimatedCube".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1802+
{ "AnimatedMorphCube".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1803+
{ "AnimatedMorphSphere".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1804+
{ "AntiqueCamera".ToLower(), Matrix.CreateScale(0.5f) },
1805+
{ "AttenuationTest".ToLower(), Matrix.CreateScale(0.3f) * Matrix.CreateTranslation(0, 4, 0) },
1806+
{ "Avocado".ToLower(), Matrix.CreateScale(50) },
1807+
{ "BarramundiFish".ToLower(), Matrix.CreateScale(10) },
1808+
{ "BoomBox".ToLower(), Matrix.CreateScale(100) * Matrix.CreateTranslation(0, 2, 0) },
1809+
{ "BoomBoxWithAxes".ToLower(), Matrix.CreateScale(100) * Matrix.CreateTranslation(0, 2, 0) },
1810+
{ "Box".ToLower(), Matrix.CreateTranslation(0, 1, 0) },
1811+
{ "Box With Spaces".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1812+
{ "BoxAnimated".ToLower(), Matrix.CreateTranslation(0, 1, 0) },
1813+
{ "BoxInterleaved".ToLower(), Matrix.CreateTranslation(0, 1, 0) },
1814+
{ "BoxTextured".ToLower(), Matrix.CreateTranslation(0, 1, 0) },
1815+
{ "BoxTexturedNonPowerOfTwo".ToLower(), Matrix.CreateTranslation(0, 1, 0) },
1816+
{ "BoxVertexColors".ToLower(), Matrix.CreateTranslation(0, 1, 0) },
1817+
{ "Buggy".ToLower(), Matrix.CreateScale(0.02f) * Matrix.CreateTranslation(0, 1, 0) },
1818+
{ "ClearCoatTest".ToLower(), Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(0, 3, 0) },
1819+
{ "Corset".ToLower(), Matrix.CreateScale(40) * Matrix.CreateTranslation(0, 1, 0) },
1820+
{ "Cube".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1821+
{ "DamagedHelmet".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1822+
{ "DragonAttenuation".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1823+
{ "EmissiveStrengthTest".ToLower(), Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(0, 3, 0) },
1824+
{ "FlightHelmet".ToLower(), Matrix.CreateScale(5) },
1825+
{ "Fox".ToLower(), Matrix.CreateScale(0.02f) },
1826+
{ "GearboxAssy".ToLower(), Matrix.CreateTranslation(100, 0, 0) },
1827+
{ "GlamVelvetSofa".ToLower(), Matrix.CreateScale(2) },
1828+
{ "InterpolationTest".ToLower(), Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(0, 2, 0) },
1829+
{ "IridescenceDielectricSpheres".ToLower(), Matrix.CreateScale(0.2f) * Matrix.CreateTranslation(0, 4, 0) },
1830+
{ "IridescenceLamp".ToLower(), Matrix.CreateScale(5) },
1831+
{ "IridescenceMetallicSpheres".ToLower(), Matrix.CreateScale(0.2f) * Matrix.CreateTranslation(0, 4, 0) },
1832+
{ "IridescenceSuzanne".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1833+
{ "IridescentDishWithOlives".ToLower(), Matrix.CreateScale(10) },
1834+
{ "Lantern".ToLower(), Matrix.CreateScale(0.2f) },
1835+
{ "MaterialsVariantsShoe".ToLower(), Matrix.CreateScale(5) },
1836+
{ "MetalRoughSpheres".ToLower(), Matrix.CreateTranslation(0, 5, 0) },
1837+
{ "MetalRoughSpheresNoTextures".ToLower(), Matrix.CreateTranslation(0, 5, 0) },
1838+
{ "MorphPrimitivesTest".ToLower(), Matrix.CreateScale(2) * Matrix.CreateTranslation(0, 1, 0) },
1839+
{ "MosquitoInAmber".ToLower(), Matrix.CreateScale(25) * Matrix.CreateTranslation(0, 1, 0) },
1840+
{ "MultiUVTest".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
1841+
{ "NormalTangentMirrorTest".ToLower(), Matrix.CreateScale(2) * Matrix.CreateTranslation(0, 2, 0) },
1842+
{ "NormalTangentTest".ToLower(), Matrix.CreateScale(2) * Matrix.CreateTranslation(0, 2, 0) },
1843+
{ "OrientationTest".ToLower(), Matrix.CreateScale(0.2f) * Matrix.CreateTranslation(0, 2, 0) },
1844+
{ "ReciprocatingSaw".ToLower(), Matrix.CreateScale(0.02f) * Matrix.CreateTranslation(0, 3, 0) },
1845+
{ "RecursiveSkeletons".ToLower(), Matrix.CreateScale(0.02f) },
1846+
};
17841847
}
17851848

17861849
class GltfAnimation

0 commit comments

Comments
 (0)