36
36
using System ;
37
37
using System . Collections . Generic ;
38
38
using System . Diagnostics ;
39
+ using System . IO ;
39
40
using System . Linq ;
40
41
41
42
namespace Orts . Viewer3D
@@ -89,8 +90,8 @@ public LightViewer(Viewer viewer, TrainCar car, TrainCarViewer carViewer)
89
90
Viewer = viewer ;
90
91
Car = car ;
91
92
CarViewer = carViewer ;
92
-
93
- LightGlowMaterial = viewer . MaterialManager . Load ( "LightGlow" ) ;
93
+
94
+ LightGlowMaterial = viewer . MaterialManager . Load ( "LightGlow" , DefineFullTexturePath ( Car . Lights . GeneralLightGlowGraphic ) ) ;
94
95
LightConeMaterial = viewer . MaterialManager . Load ( "LightCone" ) ;
95
96
96
97
UpdateState ( ) ;
@@ -102,6 +103,10 @@ public LightViewer(Viewer viewer, TrainCar car, TrainCarViewer carViewer)
102
103
{
103
104
case LightType . Glow :
104
105
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 , true ) ) ;
108
+ else
109
+ ( LightPrimitives . Last ( ) as LightGlowPrimitive ) . SpecificGlowMaterial = LightGlowMaterial ;
105
110
break ;
106
111
case LightType . Cone :
107
112
LightPrimitives . Add ( new LightConePrimitive ( this , Viewer . RenderProcess , light ) ) ;
@@ -149,6 +154,17 @@ public LightViewer(Viewer viewer, TrainCar car, TrainCarViewer carViewer)
149
154
UpdateActiveLightCone ( ) ;
150
155
}
151
156
157
+ string DefineFullTexturePath ( string textureName , bool searchSpecificTexture = false )
158
+ {
159
+ if ( File . Exists ( Path . Combine ( Path . GetDirectoryName ( Car . WagFilePath ) , textureName ) ) )
160
+ return Path . Combine ( Path . GetDirectoryName ( Car . WagFilePath ) , textureName ) ;
161
+ if ( searchSpecificTexture )
162
+ Trace . TraceWarning ( "Could not find light graphic {0} at {1}" , textureName , Path . Combine ( Path . GetDirectoryName ( Car . WagFilePath ) , textureName ) ) ;
163
+ if ( File . Exists ( Path . Combine ( Viewer . ContentPath , textureName ) ) )
164
+ return Path . Combine ( Viewer . ContentPath , textureName ) ;
165
+ return Path . Combine ( Viewer . ContentPath , "LightGlow.png" ) ;
166
+ }
167
+
152
168
void UpdateActiveLightCone ( )
153
169
{
154
170
var newLightCone = ( LightConePrimitive ) LightPrimitives . FirstOrDefault ( lm => lm is LightConePrimitive && lm . Enabled ) ;
@@ -220,9 +236,9 @@ public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
220
236
if ( ( lightPrimitive . Enabled || lightPrimitive . FadeOut ) && lightPrimitive is LightGlowPrimitive )
221
237
{
222
238
if ( ShapeXNATranslations . TryGetValue ( lightPrimitive . Light . ShapeIndex , out Matrix lightMatrix ) )
223
- frame . AddPrimitive ( LightGlowMaterial , lightPrimitive , RenderPrimitiveGroup . Lights , ref lightMatrix ) ;
239
+ frame . AddPrimitive ( ( lightPrimitive as LightGlowPrimitive ) . SpecificGlowMaterial , lightPrimitive , RenderPrimitiveGroup . Lights , ref lightMatrix ) ;
224
240
else
225
- frame . AddPrimitive ( LightGlowMaterial , lightPrimitive , RenderPrimitiveGroup . Lights , ref xnaDTileTranslation ) ;
241
+ frame . AddPrimitive ( ( lightPrimitive as LightGlowPrimitive ) . SpecificGlowMaterial , lightPrimitive , RenderPrimitiveGroup . Lights , ref xnaDTileTranslation ) ;
226
242
}
227
243
228
244
#if DEBUG_LIGHT_CONE
@@ -252,6 +268,11 @@ public void Mark()
252
268
{
253
269
LightGlowMaterial . Mark ( ) ;
254
270
LightConeMaterial . Mark ( ) ;
271
+ foreach ( var lightPrimitive in LightPrimitives )
272
+ if ( lightPrimitive is LightGlowPrimitive && lightPrimitive . Light . Graphic != null )
273
+ {
274
+ ( lightPrimitive as LightGlowPrimitive ) . SpecificGlowMaterial . Mark ( ) ;
275
+ }
255
276
}
256
277
257
278
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 +701,7 @@ public class LightGlowPrimitive : LightPrimitive
680
701
static VertexDeclaration VertexDeclaration ;
681
702
VertexBuffer VertexBuffer ;
682
703
static IndexBuffer IndexBuffer ;
704
+ public Material SpecificGlowMaterial ;
683
705
684
706
public LightGlowPrimitive ( LightViewer lightViewer , RenderProcess renderProcess , Light light )
685
707
: base ( light )
@@ -932,11 +954,11 @@ public class LightGlowMaterial : Material
932
954
{
933
955
readonly Texture2D LightGlowTexture ;
934
956
935
- public LightGlowMaterial ( Viewer viewer )
936
- : base ( viewer , null )
957
+ public LightGlowMaterial ( Viewer viewer , string textureName )
958
+ : base ( viewer , textureName )
937
959
{
938
960
// TODO: This should happen on the loader thread.
939
- LightGlowTexture = SharedTextureManager . Get ( Viewer . RenderProcess . GraphicsDevice , System . IO . Path . Combine ( Viewer . ContentPath , "Lightglow.png" ) ) ;
961
+ LightGlowTexture = SharedTextureManager . Get ( Viewer . RenderProcess . GraphicsDevice , textureName ) ;
940
962
}
941
963
942
964
public override void SetState ( GraphicsDevice graphicsDevice , Material previousMaterial )
0 commit comments