Resize() public static method

public static Resize ( TextureInfoWrapper texture, int width, int height, bool mipmaps, bool convertToNormalFormat ) : void
texture TextureInfoWrapper
width int
height int
mipmaps bool
convertToNormalFormat bool
return void
Beispiel #1
0
        public static void IMGToTexture(TexInfo Texture, bool mipmaps, bool isNormalFormat)
        {
            TextureInfoWrapper texture = Texture.texture;

            TextureConverter.InitImageBuffer();
            FileStream imgStream = new FileStream(Texture.filename, FileMode.Open, FileAccess.Read);

            imgStream.Position = 0;
            imgStream.Read(imageBuffer, 0, MAX_IMAGE_SIZE);
            imgStream.Close();

            Texture2D tex = texture.texture;

            tex.LoadImage(imageBuffer);
            bool convertToNormalFormat = texture.isNormalMap && !isNormalFormat ? true : false;
            bool hasMipmaps            = tex.mipmapCount == 1 ? false : true;

            if (Texture.loadOriginalFirst)
            {
                Texture.Resize(tex.width, tex.height);
            }
            TextureFormat format = tex.format;

            if (texture.isNormalMap)
            {
                format = TextureFormat.ARGB32;
            }
            if (Texture.needsResize)
            {
                TextureConverter.Resize(texture, Texture.resizeWidth, Texture.resizeHeight, mipmaps, convertToNormalFormat);
            }
            else if (convertToNormalFormat || hasMipmaps != mipmaps || format != tex.format)
            {
                Color32[] pixels = tex.GetPixels32();
                if (convertToNormalFormat)
                {
                    for (int i = 0; i < pixels.Length; i++)
                    {
                        pixels[i].a = pixels[i].r;
                        pixels[i].r = pixels[i].g;
                        pixels[i].b = pixels[i].g;
                    }
                }
                if (tex.format != format || hasMipmaps != mipmaps)
                {
                    tex.Resize(tex.width, tex.height, format, mipmaps);
                }
                tex.SetPixels32(pixels);
                tex.Apply(mipmaps);
            }
        }