Skip to content

Commit 2db3f07

Browse files
authored
2 parents ad883dd + 92191ed commit 2db3f07

File tree

2 files changed

+68
-26
lines changed

2 files changed

+68
-26
lines changed

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/FreightAnimations.cs

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,21 @@ public enum Type
302302
{
303303
DEFAULT
304304
}
305+
// index of visibility flag vector
306+
public enum VisibleFrom
307+
{
308+
Outside,
309+
Cab2D,
310+
Cab3D
311+
}
305312
public Type SubType;
306313
public float XOffset = 0;
307314
public float YOffset = 0;
308315
public float ZOffset = 0;
309316
public float FreightWeight = 0;
310317
public bool Flipped = false;
318+
public bool Cab3DFreightAnim = false;
319+
public bool[] Visibility = { true, false, false };
311320

312321
// additions to manage consequences of variable weight on friction and brake forces
313322
public float FullStaticORTSDavis_A = -9999;
@@ -324,34 +333,55 @@ public FreightAnimationStatic(STFReader stf)
324333
stf.MustMatch("(");
325334
stf.ParseBlock(new STFReader.TokenProcessor[] {
326335
new STFReader.TokenProcessor("subtype", ()=>
336+
{
337+
var typeString = stf.ReadStringBlock(null);
338+
switch (typeString)
339+
{
340+
default:
341+
SubType = FreightAnimationStatic.Type.DEFAULT;
342+
break;
343+
}
344+
}),
345+
new STFReader.TokenProcessor("shape", ()=>{ ShapeFileName = stf.ReadStringBlock(null); }),
346+
new STFReader.TokenProcessor("freightweight", ()=>{ FreightWeight = stf.ReadFloatBlock(STFReader.UNITS.Mass, 0); }),
347+
new STFReader.TokenProcessor("offset", ()=>{
348+
stf.MustMatch("(");
349+
XOffset = stf.ReadFloat(STFReader.UNITS.Distance, 0);
350+
YOffset = stf.ReadFloat(STFReader.UNITS.Distance, 0);
351+
ZOffset = stf.ReadFloat(STFReader.UNITS.Distance, 0);
352+
stf.MustMatch(")");
353+
}),
354+
new STFReader.TokenProcessor("flip", ()=>{ Flipped = stf.ReadBoolBlock(true);}),
355+
new STFReader.TokenProcessor("visibility", ()=>{
356+
for (int index = 0; index < 3; index++)
357+
Visibility[index] = false;
358+
foreach (var visibilityPlace in stf.ReadStringBlock("").ToLower().Replace(" ", "").Split(','))
327359
{
328-
var typeString = stf.ReadStringBlock(null);
329-
switch (typeString)
330-
{
360+
switch (visibilityPlace)
361+
{
362+
case "outside":
363+
Visibility[(int)VisibleFrom.Outside] = true;
364+
break;
365+
case "cab2d":
366+
Visibility[(int)VisibleFrom.Cab2D] = true;
367+
break;
368+
case "cab3d":
369+
Visibility[(int)VisibleFrom.Cab3D] = true;
370+
break;
331371
default:
332-
SubType = FreightAnimationStatic.Type.DEFAULT;
333372
break;
334-
}
335-
}),
336-
new STFReader.TokenProcessor("shape", ()=>{ ShapeFileName = stf.ReadStringBlock(null); }),
337-
new STFReader.TokenProcessor("freightweight", ()=>{ FreightWeight = stf.ReadFloatBlock(STFReader.UNITS.Mass, 0); }),
338-
new STFReader.TokenProcessor("offset", ()=>{
339-
stf.MustMatch("(");
340-
XOffset = stf.ReadFloat(STFReader.UNITS.Distance, 0);
341-
YOffset = stf.ReadFloat(STFReader.UNITS.Distance, 0);
342-
ZOffset = stf.ReadFloat(STFReader.UNITS.Distance, 0);
343-
stf.MustMatch(")");
344-
}),
345-
new STFReader.TokenProcessor("flip", ()=>{ Flipped = stf.ReadBoolBlock(true);}),
346-
// additions to manage consequences of variable weight on friction and brake forces
347-
new STFReader.TokenProcessor("fullortsdavis_a", ()=>{ FullStaticORTSDavis_A = stf.ReadFloatBlock(STFReader.UNITS.Force, -1); }),
348-
new STFReader.TokenProcessor("fullortsdavis_b", ()=>{ FullStaticORTSDavis_B = stf.ReadFloatBlock(STFReader.UNITS.Resistance, -1); }),
349-
new STFReader.TokenProcessor("fullortsdavis_c", ()=>{ FullStaticORTSDavis_C = stf.ReadFloatBlock(STFReader.UNITS.ResistanceDavisC, -1); }),
350-
new STFReader.TokenProcessor("fullortswagonfrontalarea", ()=>{ FullStaticORTSWagonFrontalAreaM2 = stf.ReadFloatBlock(STFReader.UNITS.AreaDefaultFT2, -1); }),
351-
new STFReader.TokenProcessor("fullortsdavisdragconstant", ()=>{ FullStaticORTSDavisDragConstant = stf.ReadFloatBlock(STFReader.UNITS.Any, -1); }),
352-
new STFReader.TokenProcessor("fullmaxbrakeforce", ()=>{ FullStaticMaxBrakeForceN = stf.ReadFloatBlock(STFReader.UNITS.Force, -1); }),
353-
new STFReader.TokenProcessor("fullmaxhandbrakeforce", ()=>{ FullStaticMaxHandbrakeForceN = stf.ReadFloatBlock(STFReader.UNITS.Force, -1); }),
354-
new STFReader.TokenProcessor("fullcentreofgravity_y", ()=>{ FullStaticCentreOfGravityM_Y = stf.ReadFloatBlock(STFReader.UNITS.Distance, -1); })
373+
}
374+
}
375+
}),
376+
// additions to manage consequences of variable weight on friction and brake forces
377+
new STFReader.TokenProcessor("fullortsdavis_a", ()=>{ FullStaticORTSDavis_A = stf.ReadFloatBlock(STFReader.UNITS.Force, -1); }),
378+
new STFReader.TokenProcessor("fullortsdavis_b", ()=>{ FullStaticORTSDavis_B = stf.ReadFloatBlock(STFReader.UNITS.Resistance, -1); }),
379+
new STFReader.TokenProcessor("fullortsdavis_c", ()=>{ FullStaticORTSDavis_C = stf.ReadFloatBlock(STFReader.UNITS.ResistanceDavisC, -1); }),
380+
new STFReader.TokenProcessor("fullortswagonfrontalarea", ()=>{ FullStaticORTSWagonFrontalAreaM2 = stf.ReadFloatBlock(STFReader.UNITS.AreaDefaultFT2, -1); }),
381+
new STFReader.TokenProcessor("fullortsdavisdragconstant", ()=>{ FullStaticORTSDavisDragConstant = stf.ReadFloatBlock(STFReader.UNITS.Any, -1); }),
382+
new STFReader.TokenProcessor("fullmaxbrakeforce", ()=>{ FullStaticMaxBrakeForceN = stf.ReadFloatBlock(STFReader.UNITS.Force, -1); }),
383+
new STFReader.TokenProcessor("fullmaxhandbrakeforce", ()=>{ FullStaticMaxHandbrakeForceN = stf.ReadFloatBlock(STFReader.UNITS.Force, -1); }),
384+
new STFReader.TokenProcessor("fullcentreofgravity_y", ()=>{ FullStaticCentreOfGravityM_Y = stf.ReadFloatBlock(STFReader.UNITS.Distance, -1); })
355385
});
356386
}
357387

@@ -364,6 +394,8 @@ public FreightAnimationStatic(FreightAnimationStatic freightAnimStatic)
364394
YOffset = freightAnimStatic.YOffset;
365395
ZOffset = freightAnimStatic.ZOffset;
366396
Flipped = freightAnimStatic.Flipped;
397+
for (int index = 0; index < 3; index++)
398+
Visibility[index] = freightAnimStatic.Visibility[index];
367399
FreightWeight = freightAnimStatic.FreightWeight;
368400

369401
// additions to manage consequences of variable weight on friction and brake forces

Source/RunActivity/Viewer3D/RollingStock/MSTSWagonViewer.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ private void UpdateAnimation(RenderFrame frame, ElapsedTime elapsedTime)
598598
// It appears that only one MSTS type FA can be used per vehicle (to be confirmed?)
599599
// For coal load variation, C should be absent (set to 1 when read in WAG file) or >0 - sets FreightAnimFlag; and A > B
600600
// To disable coal load variation and insert a static (crew) shape on the tender breech, one of the conditions indicated above
601-
if (FreightShape != null)
601+
if (FreightShape != null && !(Viewer.Camera.AttachedCar == this.MSTSWagon && Viewer.Camera.Style == Camera.Styles.ThreeDimCab))
602602
{
603603
// Define default position of shape
604604
FreightShape.Location.XNAMatrix = Car.WorldPosition.XNAMatrix;
@@ -655,6 +655,16 @@ private void UpdateAnimation(RenderFrame frame, ElapsedTime elapsedTime)
655655
{
656656
foreach (var freightAnim in FreightAnimations.Animations)
657657
{
658+
if (freightAnim.Animation is FreightAnimationStatic)
659+
{
660+
var animation = freightAnim.Animation as FreightAnimationStatic;
661+
if (!((animation.Visibility[(int)FreightAnimationStatic.VisibleFrom.Cab3D] &&
662+
Viewer.Camera.AttachedCar == this.MSTSWagon && Viewer.Camera.Style == Camera.Styles.ThreeDimCab) ||
663+
(animation.Visibility[(int)FreightAnimationStatic.VisibleFrom.Cab2D] &&
664+
Viewer.Camera.AttachedCar == this.MSTSWagon && Viewer.Camera.Style == Camera.Styles.Cab) ||
665+
(animation.Visibility[(int)FreightAnimationStatic.VisibleFrom.Outside] && (Viewer.Camera.AttachedCar != this.MSTSWagon ||
666+
(Viewer.Camera.Style != Camera.Styles.ThreeDimCab && Viewer.Camera.Style != Camera.Styles.Cab))))) continue;
667+
}
658668
if (freightAnim.FreightShape != null && !((freightAnim.Animation is FreightAnimationContinuous) && (freightAnim.Animation as FreightAnimationContinuous).LoadPerCent == 0))
659669
{
660670
freightAnim.FreightShape.Location.XNAMatrix = Car.WorldPosition.XNAMatrix;

0 commit comments

Comments
 (0)