Пример #1
0
        public static Material GetTexture(int idx)
        {
            Material ret = _vswapTexture.ContainsKey(idx) ?
                           _vswapTexture[idx] : null;

            if (ret == null)
            {
                byte[] data = new byte[VSWAP.TextureSize.Width * VSWAP.TextureSize.Height * 4];

                SpatialMaterial mat = new SpatialMaterial();

                ImageTexture tex = new ImageTexture();
                Image        img = new Image();

                System.Drawing.Bitmap bmp = VSWAP.GetTextureBitmap(Palette, (uint)idx);

                int stride = VSWAP.TextureSize.Width * 4;

                for (int y = 0; y < VSWAP.TextureSize.Height; y++)
                {
                    for (int x = 0; x < VSWAP.TextureSize.Width; x++)
                    {
                        System.Drawing.Color pixel = bmp.GetPixel(x, y);

                        data[(stride * y) + (x * 4) + 0] = pixel.R;
                        data[(stride * y) + (x * 4) + 1] = pixel.G;
                        data[(stride * y) + (x * 4) + 2] = pixel.B;
                        data[(stride * y) + (x * 4) + 3] = 255;
                    }
                }

                img.CreateFromData(
                    VSWAP.TextureSize.Width,
                    VSWAP.TextureSize.Height,
                    false, Image.Format.Rgba8, data);

                tex.CreateFromImage(img, (uint)Texture.FlagsEnum.Repeat);

                mat.AlbedoTexture  = tex;
                mat.ParamsCullMode = SpatialMaterial.CullMode.Back;

                ret = mat;

                _vswapTexture.Add(idx, ret);
            }

            return(ret);
        }