Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 public MyTileTexture(PixelBuffer image, int cellSize)
 {
     this.m_cellCoords = new Vector2I[0x10];
     this.m_stride     = image.RowStride;
     this.m_cellSize   = new Vector2I(cellSize);
     this.m_data       = image.GetPixels <TPixel>(0);
     this.PrepareCellCoords();
 }
Esempio n. 3
0
        public MyTileTexture(PixelBuffer image, int cellSize)
        {
            Debug.Assert(4 * cellSize >= image.Width && 4 * cellSize >= image.Height, "Image does not fit cells of the provided cell size");
            m_stride   = image.RowStride;
            m_cellSize = new Vector2I(cellSize);
            m_data     = image.GetPixels <Pixel>();

            PrepareCellCoords();
        }
        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);
        }