private Image TryGetPlanetTexture(string name, MyModContext context, string p, out string fullPath) { bool found = false; name += p; fullPath = Path.Combine(context.ModPathData, "PlanetDataFiles", name) + ".png"; // Check for modded textures if (!context.IsBaseGame) { if (!MyFileSystem.FileExists(fullPath)) { fullPath = Path.Combine(context.ModPathData, "PlanetDataFiles", name) + ".dds"; if (MyFileSystem.FileExists(fullPath)) { found = true; } } else { found = true; } } // Check for default textures if (!found) { fullPath = Path.Combine(m_planetDataFolder, name) + ".png"; if (!MyFileSystem.FileExists(fullPath)) { fullPath = Path.Combine(m_planetDataFolder, name) + ".dds"; if (!MyFileSystem.FileExists(fullPath)) { return(null); } } } if (fullPath.Contains(".sbm")) { string archivePath = fullPath.Substring(0, fullPath.IndexOf(".sbm") + 4); string fileRelativeArchivePath = fullPath.Replace(archivePath + "\\", ""); using (var sbm = VRage.Compression.MyZipArchive.OpenOnFile(archivePath)) { try { return(SharpDXImage.Load(sbm.GetFile(fileRelativeArchivePath).GetStream())); } catch (Exception ex) { MyDebug.FailRelease("Failed to load existing " + p + " file from .sbm archive. " + fullPath); return(null); } } } return(SharpDXImage.Load(fullPath)); }
private static Image LoadTexture(string path) { if (!MyFileSystem.FileExists(path)) { return(null); } using (Stream textureStream = MyFileSystem.OpenRead(path)) { return(textureStream != null?SharpDXImage.Load(textureStream) : null); } }
public MyTileTexture <byte> GetTerrainBlendTexture(MyPlanetMaterialBlendSettings settings) { MyTileTexture <byte> tex; string path = settings.Texture; int cellSize = settings.CellSize; if (!m_ditherTilesets.TryGetValue(path, out tex)) { string fullPath = Path.Combine(MyFileSystem.ContentPath, path) + ".png"; if (!File.Exists(fullPath)) { fullPath = Path.Combine(MyFileSystem.ContentPath, path) + ".dds"; } SharpDXImage image = null; try { image = SharpDXImage.Load(fullPath); } catch (Exception e) { MyLog.Default.WriteLine(e.Message); } if (image == null) { return(MyTileTexture <byte> .Default); } PixelBuffer buffer = image.GetPixelBuffer(0, 0, 0); Debug.Assert(buffer.Format == Format.R8_UNorm); if (buffer.Format != Format.R8_UNorm) { return(MyTileTexture <byte> .Default); } tex = new MyTileTexture <byte>(buffer, cellSize); image.Dispose(); } return(tex); }