Skip to content

Commit 278d8ff

Browse files
committed
Only support GPU-friendly texture formats for particles
1 parent 58de4c3 commit 278d8ff

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

Source/Documentation/Manual/physics.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,8 @@ be included to further customize effect emitters:
26112611
particles from this emitter. The default texture is "smokemain.ace" for steam-type emitters and
26122612
"dieselsmoke.ace" for diesel-type emitters. If the texture cannot be found from the engine's/wagon's
26132613
folder, then the ``GLOBAL\TEXTURES`` folder is checked, and if the texture is not there the ``Content``
2614-
folder included with OR is checked. Allowed texture formats are ``.png, .jpg, .bmp, .gif, .ace, or .dds``.
2614+
folder included with OR is checked. OR will search for any ``.ace`` or ``.dds`` textures with the name
2615+
specified, though .dds is preferred over .ace.
26152616
A path to a texture can also be used, such as ``ORTSGraphic ( "..\\SmokeTextures\\steam.dds" )``, to search
26162617
for textures not in the same folder as the engine or wagon.
26172618
- ``ORTSGraphicAtlasLayout ( w h )`` -- Particle textures generally include multiple sprites in a single file

Source/RunActivity/Viewer3D/Materials.cs

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,12 @@ public Texture2D Get(string path, Texture2D defaultTexture, bool required = fals
6565
return defaultTexture;
6666

6767
path = path.ToLowerInvariant();
68-
var ext = Path.GetExtension(path);
69-
7068
if (!Textures.ContainsKey(path))
7169
{
7270
try
7371
{
7472
Texture2D texture;
75-
if (ext == ".dds")
73+
if (Path.GetExtension(path) == ".dds")
7674
{
7775
if (File.Exists(path))
7876
{
@@ -91,10 +89,10 @@ public Texture2D Get(string path, Texture2D defaultTexture, bool required = fals
9189
else return defaultTexture;
9290
}
9391
}
94-
else if (ext == ".ace")
92+
else if (Path.GetExtension(path) == ".ace")
9593
{
9694
var alternativeTexture = Path.ChangeExtension(path, ".dds");
97-
95+
9896
if (File.Exists(alternativeTexture))
9997
{
10098
DDSLib.DDSFromFile(alternativeTexture, GraphicsDevice, true, out texture);
@@ -147,30 +145,7 @@ Texture2D invalid()
147145
}
148146
}
149147
else
150-
{
151-
using (var stream = File.OpenRead(path))
152-
{
153-
if (ext == ".gif" || ext == ".jpg" || ext == ".png")
154-
texture = Texture2D.FromStream(GraphicsDevice, stream);
155-
else if (ext == ".bmp")
156-
{
157-
using (var image = System.Drawing.Image.FromStream(stream))
158-
{
159-
using (var memoryStream = new MemoryStream())
160-
{
161-
image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
162-
memoryStream.Seek(0, SeekOrigin.Begin);
163-
texture = Texture2D.FromStream(GraphicsDevice, memoryStream);
164-
}
165-
}
166-
}
167-
else
168-
{
169-
Trace.TraceWarning("Unsupported texture format: {0}", path);
170-
return defaultTexture;
171-
}
172-
}
173-
}
148+
return defaultTexture;
174149

175150
Textures.Add(path, texture);
176151
return texture;

Source/RunActivity/Viewer3D/ParticleEmitter.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,21 @@ public void Initialize(string defaultTextureName)
8787
else
8888
TexturePath = defaultTextureName;
8989

90+
string noExtension = Path.ChangeExtension(TexturePath, null);
91+
92+
string wagPath = Path.Combine(Path.GetDirectoryName(Emitter.CarViewer.Car.WagFilePath), noExtension);
93+
string globalPath = Path.Combine(Viewer.Simulator.BasePath + @"\GLOBAL\TEXTURES\", noExtension);
94+
string contentPath = Path.Combine(Viewer.ContentPath, noExtension);
95+
9096
// Texture location preference is eng/wag folder -> MSTS GLOBAL\TEXTURES folder -> OR CONTENT folder
91-
if (File.Exists(Path.Combine(Path.GetDirectoryName(Emitter.CarViewer.Car.WagFilePath), TexturePath)))
92-
TexturePath = Path.Combine(Path.GetDirectoryName(Emitter.CarViewer.Car.WagFilePath), TexturePath);
93-
else if (File.Exists(Path.Combine(Viewer.Simulator.BasePath + @"\GLOBAL\TEXTURES\", TexturePath)))
94-
TexturePath = Path.Combine(Viewer.Simulator.BasePath + @"\GLOBAL\TEXTURES\", TexturePath);
95-
else if (customTexture && File.Exists(Path.Combine(Viewer.ContentPath, TexturePath)))
96-
TexturePath = Path.Combine(Viewer.ContentPath, TexturePath);
97+
// File type agnostic: We should detect a match if a .ace OR .dds is present, regardless of the specific file type requested
98+
// We give the material manager the path to the .dds file, but it will automatically load the .ace file if the .dds is missing
99+
if (File.Exists(wagPath + ".dds") || File.Exists(wagPath + ".ace"))
100+
TexturePath = wagPath + ".dds";
101+
else if (File.Exists(globalPath + ".dds") || File.Exists(globalPath + ".ace"))
102+
TexturePath = globalPath + ".dds";
103+
else if (File.Exists(contentPath + ".dds") || File.Exists(contentPath + ".ace"))
104+
TexturePath = contentPath + ".dds";
97105
else // Fall back to default texture in CONTENT folder
98106
{
99107
TexturePath = Path.Combine(Viewer.ContentPath, defaultTextureName);

0 commit comments

Comments
 (0)