3636using System ;
3737using System . Collections . Generic ;
3838using System . Diagnostics ;
39+ using System . IO ;
3940using System . Linq ;
4041
4142namespace Orts . Viewer3D
@@ -89,8 +90,8 @@ public LightViewer(Viewer viewer, TrainCar car, TrainCarViewer carViewer)
8990 Viewer = viewer ;
9091 Car = car ;
9192 CarViewer = carViewer ;
92-
93- LightGlowMaterial = viewer . MaterialManager . Load ( "LightGlow" ) ;
93+
94+ LightGlowMaterial = viewer . MaterialManager . Load ( "LightGlow" , DefineFullTexturePath ( Car . Lights . GeneralLightGlowGraphic ) ) ;
9495 LightConeMaterial = viewer . MaterialManager . Load ( "LightCone" ) ;
9596
9697 UpdateState ( ) ;
@@ -102,6 +103,8 @@ public LightViewer(Viewer viewer, TrainCar car, TrainCarViewer carViewer)
102103 {
103104 case LightType . Glow :
104105 LightPrimitives . Add ( new LightGlowPrimitive ( this , Viewer . RenderProcess , light ) ) ;
106+ if ( light . Graphic != null )
107+ ( LightPrimitives . Last ( ) as LightGlowPrimitive ) . SpecificGlowMaterial = viewer . MaterialManager . Load ( "LightGlow" , DefineFullTexturePath ( light . Graphic ) ) ;
105108 break ;
106109 case LightType . Cone :
107110 LightPrimitives . Add ( new LightConePrimitive ( this , Viewer . RenderProcess , light ) ) ;
@@ -149,6 +152,15 @@ public LightViewer(Viewer viewer, TrainCar car, TrainCarViewer carViewer)
149152 UpdateActiveLightCone ( ) ;
150153 }
151154
155+ string DefineFullTexturePath ( string textureName )
156+ {
157+ if ( File . Exists ( Path . Combine ( Path . GetDirectoryName ( Car . WagFilePath ) , textureName ) ) )
158+ return Path . Combine ( Path . GetDirectoryName ( Car . WagFilePath ) , textureName ) ;
159+ if ( File . Exists ( Path . Combine ( Viewer . ContentPath , textureName ) ) )
160+ return Path . Combine ( Viewer . ContentPath , textureName ) ;
161+ return Path . Combine ( Viewer . ContentPath , "LightGlow.png" ) ;
162+ }
163+
152164 void UpdateActiveLightCone ( )
153165 {
154166 var newLightCone = ( LightConePrimitive ) LightPrimitives . FirstOrDefault ( lm => lm is LightConePrimitive && lm . Enabled ) ;
@@ -220,9 +232,9 @@ public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
220232 if ( ( lightPrimitive . Enabled || lightPrimitive . FadeOut ) && lightPrimitive is LightGlowPrimitive )
221233 {
222234 if ( ShapeXNATranslations . TryGetValue ( lightPrimitive . Light . ShapeIndex , out Matrix lightMatrix ) )
223- frame . AddPrimitive ( LightGlowMaterial , lightPrimitive , RenderPrimitiveGroup . Lights , ref lightMatrix ) ;
235+ frame . AddPrimitive ( lightPrimitive . Light . Graphic != null ? ( lightPrimitive as LightGlowPrimitive ) . SpecificGlowMaterial : LightGlowMaterial , lightPrimitive , RenderPrimitiveGroup . Lights , ref lightMatrix ) ;
224236 else
225- frame . AddPrimitive ( LightGlowMaterial , lightPrimitive , RenderPrimitiveGroup . Lights , ref xnaDTileTranslation ) ;
237+ frame . AddPrimitive ( lightPrimitive . Light . Graphic != null ? ( lightPrimitive as LightGlowPrimitive ) . SpecificGlowMaterial : LightGlowMaterial , lightPrimitive , RenderPrimitiveGroup . Lights , ref xnaDTileTranslation ) ;
226238 }
227239
228240#if DEBUG_LIGHT_CONE
@@ -252,6 +264,11 @@ public void Mark()
252264 {
253265 LightGlowMaterial . Mark ( ) ;
254266 LightConeMaterial . Mark ( ) ;
267+ foreach ( var lightPrimitive in LightPrimitives )
268+ if ( lightPrimitive is LightGlowPrimitive && lightPrimitive . Light . Graphic != null )
269+ {
270+ ( lightPrimitive as LightGlowPrimitive ) . SpecificGlowMaterial . Mark ( ) ;
271+ }
255272 }
256273
257274 public static void CalculateLightCone ( LightState lightState , out Vector3 position , out Vector3 direction , out float angle , out float radius , out float distance , out Vector4 color )
@@ -680,6 +697,7 @@ public class LightGlowPrimitive : LightPrimitive
680697 static VertexDeclaration VertexDeclaration ;
681698 VertexBuffer VertexBuffer ;
682699 static IndexBuffer IndexBuffer ;
700+ public Material SpecificGlowMaterial ;
683701
684702 public LightGlowPrimitive ( LightViewer lightViewer , RenderProcess renderProcess , Light light )
685703 : base ( light )
@@ -932,11 +950,11 @@ public class LightGlowMaterial : Material
932950 {
933951 readonly Texture2D LightGlowTexture ;
934952
935- public LightGlowMaterial ( Viewer viewer )
936- : base ( viewer , null )
953+ public LightGlowMaterial ( Viewer viewer , string textureName )
954+ : base ( viewer , textureName )
937955 {
938956 // TODO: This should happen on the loader thread.
939- LightGlowTexture = SharedTextureManager . Get ( Viewer . RenderProcess . GraphicsDevice , System . IO . Path . Combine ( Viewer . ContentPath , "Lightglow.png" ) ) ;
957+ LightGlowTexture = SharedTextureManager . Get ( Viewer . RenderProcess . GraphicsDevice , textureName ) ;
940958 }
941959
942960 public override void SetState ( GraphicsDevice graphicsDevice , Material previousMaterial )
0 commit comments