public MyHeightDetailTexture GetDetailMap(string path) { MyHeightDetailTexture texture; string str = Path.Combine(MyFileSystem.ContentPath, path); str = !MyFileSystem.FileExists(str + ".png") ? (str + ".dds") : (str + ".png"); using (Image image = this.LoadTexture(str)) { if (image != null) { PixelBuffer buffer = image.GetPixelBuffer(0, 0, 0); if (buffer.Format == Format.R8_UNorm) { texture = new MyHeightDetailTexture(buffer.GetPixels <byte>(0), (uint)buffer.Height); image.Dispose(); } else { string msg = $"Detail map '{str}' could not be loaded, expected format R8_UNorm, got {buffer.Format} instead."; MyLog.Default.WriteLine(msg); return(null); } } else { texture = new MyHeightDetailTexture(new byte[1], 1); } } return(texture); }
public MyHeightDetailTexture GetDetailMap(string path) { if (m_first) { PreloadCrashingData(); m_first = false; } MyHeightDetailTexture value; if (m_detailTextures.TryGetValue(path, out value)) { return(value); } string fullPath = Path.Combine(MyFileSystem.ContentPath, path); if (MyFileSystem.FileExists(fullPath + ".png")) { fullPath += ".png"; } else { fullPath += ".dds"; } using (var image = LoadTexture(fullPath)) { if (image == null) { value = new MyHeightDetailTexture(new byte[1], 1); } else { PixelBuffer buffer = image.GetPixelBuffer(0, 0, 0); if (buffer.Format != Format.R8_UNorm) { string err = String.Format("Detail map '{0}' could not be loaded, expected format R8_UNorm, got {1} instead.", fullPath, buffer.Format); Debug.Fail(err); MyLog.Default.WriteLine(err); return(null); } value = new MyHeightDetailTexture(buffer.GetPixels <byte>(), (uint)buffer.Height); } } m_detailTextures[path] = value; return(value); }
public MyHeightDetailTexture GetDetailMap(string path) { if (m_first) { PreloadCrashingData(); m_first = false; } MyHeightDetailTexture value; if (m_detailTextures.TryGetValue(path, out value)) { return value; } string fullPath = Path.Combine(MyFileSystem.ContentPath, path); if (MyFileSystem.FileExists(fullPath + ".png")) { fullPath += ".png"; } else { fullPath += ".dds"; } using (var image = LoadTexture(fullPath)) { if (image == null) { value = new MyHeightDetailTexture(new byte[1], 1); } else { PixelBuffer buffer = image.GetPixelBuffer(0, 0, 0); if (buffer.Format != Format.R8_UNorm) { string err = String.Format("Detail map '{0}' could not be loaded, expected format R8_UNorm, got {1} instead.", fullPath, buffer.Format); Debug.Fail(err); MyLog.Default.WriteLine(err); return null; } value = new MyHeightDetailTexture(buffer.GetPixels<byte>(), (uint)buffer.Height); image.Dispose(); } } m_detailTextures[path] = value; return value; }
public void Init(MyPlanetSurfaceDetail def, float faceSize) { m_detail = MyHeightMapLoadingSystem.Static.GetDetailMap(def.Texture); Size = def.Size; Factor = faceSize / Size; m_min = (float)Math.Cos(MathHelper.ToRadians(def.Slope.Max)); m_max = (float)Math.Cos(MathHelper.ToRadians(def.Slope.Min)); m_in = (float)Math.Cos(MathHelper.ToRadians(def.Slope.Max - def.Transition)); m_out = (float)Math.Cos(MathHelper.ToRadians(def.Slope.Min + def.Transition)); m_inRecip = 1f / (m_in - m_min); m_outRecip = 1f / (m_max - m_out); m_mid = (float)Math.Cos(MathHelper.ToRadians((def.Slope.Max + def.Slope.Min) / 2)); Scale = def.Scale; }