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); }
public MyHeightmapFace GetHeightMap(string folderName, string faceName, MyModContext context) { ProfilerShort.Begin("MyHeightmapLoadingSystem::GetHeightMap()"); if (m_first) { PreloadCrashingData(); m_first = false; } string fullPath = null; bool found = false; // Look for modded textures if (!context.IsBaseGame) { fullPath = Path.Combine(Path.Combine(context.ModPathData, "PlanetDataFiles"), folderName, faceName); if (MyFileSystem.FileExists(fullPath + ".png")) { found = true; fullPath += ".png"; } else if (MyFileSystem.FileExists(fullPath + ".dds")) { found = true; fullPath += ".dds"; } } // Use default ones if (!found) { fullPath = Path.Combine(m_planetDataFolder, folderName, faceName); if (MyFileSystem.FileExists(fullPath + ".png")) { found = true; fullPath += ".png"; } else if (MyFileSystem.FileExists(fullPath + ".dds")) { fullPath += ".dds"; } } MyHeightmapFace value; if (m_heightMaps.TryGetValue(fullPath, out value)) { ProfilerShort.End(); return(value); } try { using (SharpDXImage image = LoadTexture(fullPath)) { if (image == null) { MyLog.Default.WriteLine("Could not load texture {0}, no suitable format found. " + fullPath); } else { PixelBuffer buffer = image.GetPixelBuffer(0, 0, 0); value = new MyHeightmapFace(buffer.Height); if (buffer.Format == Format.R16_UNorm) { PrepareHeightMap(value, buffer); } else if (buffer.Format == Format.R8_UNorm) { PrepareHeightMap8Bit(value, buffer); } else { MyDebug.FailRelease(String.Format("Heighmap texture {0}: Invalid format {1} (expecting R16_UNorm or R8_UNorm).", fullPath, buffer.Format)); } buffer = null; } } m_heightMaps[fullPath] = value; } catch (Exception e) { MyLog.Default.WriteLine(e.Message); } ProfilerShort.End(); return(value); }