Skip to content

Commit

Permalink
Automatic merge of T1.5.1-271-g58e67675d and 34 pull requests
Browse files Browse the repository at this point in the history
- Pull request #570 at 6b37025: Experimental glTF 2.0 support with PBR lighting
- Pull request #722 at fb9079e: Fix Windows Forms deprecations in ActivityEditor
- Pull request #732 at 83002d7: Improvements for air brakes
- Pull request #751 at f947f29: Web interface to control cab controls with external hardware
- Pull request #753 at ab8fe32: Extends CabControls for user input
- Pull request #767 at 4cb5c77: Refine sunrise and sunset
- Pull request #769 at 1a99f43: Partial turntables https://blueprints.launchpad.net/or/+spec/partial-turntable
- Pull request #771 at c380043: Action on Hold Signal is no longer invalidated if train is not stoppe…
- Pull request #772 at 36c3662: Update tt train
- Pull request #774 at d3f8c2e: Use variable OrgAINumber for all train to train references
- Pull request #775 at d84c8d8: Update turntable pools
- Pull request #776 at 7b6af67: Update Receivers in Viewer.cs
- Pull request #777 at 7724f2b: Save and restore ClearMovingTable action (for timetables)
- Pull request #778 at 779a819: Correction for player locomotive on turntable
- Pull request #779 at 87c34a7: Remove forced processed ClearSection actions
- Pull request #780 at 5b3f246: Process passing time
- Pull request #781 at 4d9c3fb: Correct update of pending speed limits for timetable mode
- Pull request #782 at 23c41b5: Nu full physics update is required for trains in state AIStatic
- Pull request #783 at 083bc6c: Move CreateInPool from AI to Pools
- Pull request #784 at 1c37be3: Incorrect distance along track
- Pull request #785 at fd121be: Incorrect calculation of distance to train ahead
- Pull request #786 at f2c5d2d: Improve syntax check on timetable files
- Pull request #787 at e0ad658: Improve debug output for turntable pools
- Pull request #788 at 94a73d5: Improve Debug Outputs for TTTrain.cs
- Pull request #789 at 81b11f7: Avoid error on inserting train without start time
- Pull request #790 at 36a9921: Correct crash in TrainCar.cs
- Pull request #791 at 5bc890b: Correct update for Switchstand signalscript function
- Pull request #792 at f6c16fb: Correct required actions
- Pull request #793 at 8897021: Correct errors in Turntables.cs
- Pull request #794 at 6d2bf04: Use reverse path in TT Pool
- Pull request #795 at 79979e2: Accept SpeedMPS as dimension for Approach Control Speed definition
- Pull request #796 at a67ee61: fix: Resume from Save fails - filenames do not match
- Pull request #797 at 7ced1fe: To use enum for ControlGearBoxType
- Pull request #798 at 4b6141d: Temporary bug fix for https://bugs.launchpad.net/or/+bug/2004100 Casting error crash
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
9 changes: 8 additions & 1 deletion Source/ORTS.Common/ConsistGenerator.cs
Expand Up @@ -93,11 +93,18 @@ public static Stream GetConsist(string requestedPath)
{
GltfVisualTestRun = true;

var mm = Path.GetFileNameWithoutExtension(requestedPath).Split('&').ElementAtOrDefault(1);
var nn = int.TryParse(Path.GetFileNameWithoutExtension(requestedPath).Split('#').ElementAtOrDefault(1), out var requestedModelNumberrrr);
var mmm = Directory.EnumerateFileSystemEntries(baseDir, "*.*", SearchOption.AllDirectories)
.Where(f => !f.Contains(Path.Combine(baseDir, "2.0")) && (f.EndsWith(".gltf") || f.EndsWith(".glb")))
.Select(f => Path.GetFileNameWithoutExtension(f))
.Concat(Directory.EnumerateDirectories(Path.Combine(baseDir, "2.0")));

var models = Directory.EnumerateFileSystemEntries(baseDir, "*.*", SearchOption.AllDirectories)
.Where(f => !f.Contains(Path.Combine(baseDir, "2.0")) && (f.EndsWith(".gltf") || f.EndsWith(".glb")))
.Select(f => Path.GetFileNameWithoutExtension(f))
.Concat(Directory.EnumerateDirectories(Path.Combine(baseDir, "2.0")))
.Where((m, n) => m == (Path.GetFileNameWithoutExtension(requestedPath).Split('&').ElementAtOrDefault(1) ?? m) &&
.Where((m, n) => Path.GetFileName(m) == (Path.GetFileNameWithoutExtension(requestedPath).Split('&').ElementAtOrDefault(1) ?? Path.GetFileName(m)) &&
n == (int.TryParse(Path.GetFileNameWithoutExtension(requestedPath).Split('#').ElementAtOrDefault(1), out var requestedModelNumber) ? requestedModelNumber : n));

var uid = 0;
Expand Down
Expand Up @@ -2723,13 +2723,11 @@ protected virtual void UpdateHornAndBell(float elapsedClockSeconds)
{
SignalEvent(Event.BellOn);
if (Train.TrainType != Train.TRAINTYPE.REMOTE && MPManager.IsMultiPlayer()) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 1)).ToString());
if (ConsistGenerator.GltfVisualTestRun) Train.SignalEvent(Event.BellOn);
}
else if (!Bell && PreviousBell)
{
SignalEvent(Event.BellOff);
if (Train.TrainType != Train.TRAINTYPE.REMOTE && MPManager.IsMultiPlayer()) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 0)).ToString());
if (ConsistGenerator.GltfVisualTestRun) Train.SignalEvent(Event.BellOff);
}

PreviousHorn = Horn;
Expand Down Expand Up @@ -5027,6 +5025,10 @@ public override void SignalEvent(Event evt)
}
break;
}
case Event.GenericItem1On: if (ConsistGenerator.GltfVisualTestRun) GenericItem1 = true; break;
case Event.GenericItem1Off: if (ConsistGenerator.GltfVisualTestRun) GenericItem1 = false; break;
case Event.GenericItem2On: if (ConsistGenerator.GltfVisualTestRun) GenericItem2 = true; break;
case Event.GenericItem2Off: if (ConsistGenerator.GltfVisualTestRun) GenericItem2 = false; break;
}

base.SignalEvent(evt);
Expand Down
43 changes: 19 additions & 24 deletions Source/RunActivity/Viewer3D/GltfShape.cs
Expand Up @@ -54,10 +54,10 @@ public class GltfShape : SharedShape
int SkeletonRootNode;
public bool MsfsFlavoured;

internal ImmutableArray<Vector3> Scales;
internal ImmutableArray<Quaternion> Rotations;
internal ImmutableArray<Vector3> Translations;
internal ImmutableArray<float[]> Weights;
internal Vector3[] Scales;
internal Quaternion[] Rotations;
internal Vector3[] Translations;
internal float[][] Weights;

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

static readonly Stack<int> TempStack = new Stack<int>(); // (nodeNumber, parentIndex)
static readonly string[] TestControls = new[] { "WIPER", "ORTSBELL", "ORTSITEM1CONTINUOUS", "ORTSITEM1CONTINUOUS" };
static readonly string[] TestControls = new[] { "WIPER", "ORTSITEM1CONTINUOUS", "ORTSITEM2CONTINUOUS" };

public GltfDistanceLevel(GltfShape shape, int lodId, Gltf gltfFile, string gltfFileName)
{
Expand Down Expand Up @@ -455,10 +455,10 @@ public GltfDistanceLevel(GltfShape shape, int lodId, Gltf gltfFile, string gltfF
if (lodId == 0)
{
shape.Matrices = Matrices.ToArray();
shape.Scales = Scales;
shape.Rotations = Rotations;
shape.Translations = Translations;
shape.Weights = Weights;
shape.Scales = Scales.ToArray();
shape.Rotations = Rotations.ToArray();
shape.Translations = Translations.ToArray();
shape.Weights = Weights.ToArray();

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

if (ConsistGenerator.GltfVisualTestRun)
{
// Assign the first four animations to Wipers [V], Bell [Shift+B], Item1Continuous [Shift+,], Item2Continuous [Shift+.] respectively,
// Assign the first four animations to Wipers [V], Item1Continuous [Shift+,], Item2Continuous [Shift+.] respectively,
// because these are the ones capable of playing a loop.
for (var i = 0; i < shape.GltfAnimations.Count; i++)
if (i < TestControls.Length)
shape.MatrixNames[i] = TestControls[i];
shape.MatrixNames[i] = TestControls[i % TestControls.Length];
}
}
}
Expand Down Expand Up @@ -1702,7 +1701,7 @@ public override int GetAnimationParent(int animationNumber)
public override Matrix GetMatrixProduct(int iNode) => base.GetMatrixProduct(iNode) * PlusZToForward;
public override bool IsAnimationArticulation(int number) => GltfAnimations?.ElementAtOrDefault(number)?.Channels?.FirstOrDefault()?.TimeArray == null;
public override int GetAnimationTargetNode(int animationId) => GltfAnimations?.ElementAtOrDefault(animationId)?.Channels?.FirstOrDefault()?.TargetNode ?? 0;
public override int GetAnimationNamesCount() => EnableAnimations ? GltfAnimations?.Count ?? 0 : 0;
public override int GetAnimationNamesCount() => EnableAnimations || ConsistGenerator.GltfVisualTestRun ? GltfAnimations?.Count ?? 0 : 0;

public bool HasAnimation(int number) => GltfAnimations?.ElementAtOrDefault(number)?.Channels?.FirstOrDefault() != null;
public float GetAnimationLength(int number) => GltfAnimations?.ElementAtOrDefault(number)?.Channels?.Select(c => c.TimeMax).Max() ?? 0;
Expand All @@ -1714,7 +1713,7 @@ public override int GetAnimationParent(int animationNumber)
/// <param name="time">Actual time in the animation clip in seconds.</param>
public void Animate(int animationNumber, float time, Matrix[] animatedMatrices)
{
if (!EnableAnimations)
if (!EnableAnimations && !ConsistGenerator.GltfVisualTestRun)
return;

foreach (var channel in GltfAnimations[animationNumber].Channels)
Expand All @@ -1740,31 +1739,27 @@ public void Animate(int animationNumber, float time, Matrix[] animatedMatrices)
case AnimationSampler.InterpolationEnum.STEP: amount = 0; break;
default: amount = 0; break;
}
// 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.
var scale = Scales[channel.TargetNode];
var rotation = Rotations[channel.TargetNode];
var translation = Translations[channel.TargetNode];
switch (channel.Path)
{
case AnimationChannelTarget.PathEnum.translation:
translation = channel.Interpolation == AnimationSampler.InterpolationEnum.CUBICSPLINE
Translations[channel.TargetNode] = channel.Interpolation == AnimationSampler.InterpolationEnum.CUBICSPLINE
? Vector3.Hermite(channel.OutputVector3[Property(frame1)], channel.OutputVector3[OutTangent(frame2)], channel.OutputVector3[Property(frame2)], channel.OutputVector3[InTangent(frame2)], amount)
: Vector3.Lerp(channel.OutputVector3[frame1], channel.OutputVector3[frame2], amount);
break;
case AnimationChannelTarget.PathEnum.rotation:
rotation = channel.Interpolation == AnimationSampler.InterpolationEnum.CUBICSPLINE
Rotations[channel.TargetNode] = channel.Interpolation == AnimationSampler.InterpolationEnum.CUBICSPLINE
? CsInterp(channel.OutputQuaternion[Property(frame1)], channel.OutputQuaternion[OutTangent(frame2)], channel.OutputQuaternion[Property(frame2)], channel.OutputQuaternion[InTangent(frame2)], amount)
: Quaternion.Slerp(channel.OutputQuaternion[frame1], channel.OutputQuaternion[frame2], amount);
break;
case AnimationChannelTarget.PathEnum.scale:
scale = channel.Interpolation == AnimationSampler.InterpolationEnum.CUBICSPLINE
Scales[channel.TargetNode] = channel.Interpolation == AnimationSampler.InterpolationEnum.CUBICSPLINE
? Vector3.Hermite(channel.OutputVector3[Property(frame1)], channel.OutputVector3[OutTangent(frame2)], channel.OutputVector3[Property(frame2)], channel.OutputVector3[InTangent(frame2)], amount)
: Vector3.Lerp(channel.OutputVector3[frame1], channel.OutputVector3[frame2], amount);
break;
case AnimationChannelTarget.PathEnum.weights:
default: break;
}
animatedMatrices[channel.TargetNode] = Matrix.CreateScale(scale) * Matrix.CreateFromQuaternion(rotation) * Matrix.CreateTranslation(translation);
animatedMatrices[channel.TargetNode] = Matrix.CreateScale(Scales[channel.TargetNode]) * Matrix.CreateFromQuaternion(Rotations[channel.TargetNode]) * Matrix.CreateTranslation(Translations[channel.TargetNode]);
}
}

Expand Down Expand Up @@ -1840,13 +1835,13 @@ public void Animate(int animationNumber, float time, Matrix[] animatedMatrices)
{ "SheenChair".ToLower(), Matrix.CreateScale(2) },
{ "SheenCloth".ToLower(), Matrix.CreateScale(50) },
{ "SpecGlossVsMetalRough".ToLower(), Matrix.CreateScale(7) * Matrix.CreateTranslation(0, 2, 0) },
{ "SpecularTest".ToLower(), Matrix.CreateScale(3) * Matrix.CreateTranslation(0, 2, 0) },
{ "SpecularTest".ToLower(), Matrix.CreateScale(5) * Matrix.CreateTranslation(0, 2, 0) },
{ "StainedGlassLamp".ToLower(), Matrix.CreateScale(3) },
{ "Suzanne".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
{ "TextureCoordinateTest".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
{ "TextureEncodingTest".ToLower(), Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(0, 3, 0) },
{ "TextureLinearInterpolationTest".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
{ "TextureSettingsTest".ToLower(), Matrix.CreateTranslation(0, 6, 0) },
{ "TextureSettingsTest".ToLower(), Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(0, 4, 0) },
{ "TextureTransformMultiTest".ToLower(), Matrix.CreateScale(2) * Matrix.CreateTranslation(0, 4, 0) },
{ "TextureTransformTest".ToLower(), Matrix.CreateTranslation(0, 2, 0) },
{ "ToyCar".ToLower(), Matrix.CreateScale(80) * Matrix.CreateTranslation(0, 2, 0)},
Expand Down

0 comments on commit cacdda1

Please sign in to comment.