ActiveTextureManagement.TextureConverter.GetReadable C# (CSharp) Method

GetReadable() public static method

public static GetReadable ( TexInfo Texture, bool mipmaps ) : void
Texture TexInfo
mipmaps bool
return void
        public static void GetReadable(TexInfo Texture, bool mipmaps)
        {
            String mbmPath = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".mbm";
            String pngPath = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".png";
            String pngPathTruecolor = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".truecolor";
            String jpgPath = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".jpg";
            String tgaPath = KSPUtil.ApplicationRootPath + "GameData/" + Texture.name + ".tga";
            if (File.Exists(pngPath) || File.Exists(pngPathTruecolor) || File.Exists(jpgPath) || File.Exists(tgaPath) || File.Exists(mbmPath))
            {
                Texture2D tex = new Texture2D(2, 2);
                String name;
                if (Texture.name.Length > 0)
                {
                    name = Texture.name;
                }
                else
                {
                    name = Texture.name;
                }

                TextureInfoWrapper newTexture = new TextureInfoWrapper(Texture.file, tex, Texture.isNormalMap, true, false);
                Texture.texture = newTexture;
                newTexture.name = Texture.name;
                if (File.Exists(pngPath))
                {
                    Texture.filename = pngPath;
                    IMGToTexture(Texture, mipmaps, false);
                }
                else if (File.Exists(pngPathTruecolor))
                {
                    Texture.filename = pngPathTruecolor;
                    IMGToTexture(Texture, mipmaps, false);
                }
                else if (File.Exists(jpgPath))
                {
                    Texture.filename = jpgPath;
                    IMGToTexture(Texture, mipmaps, false);
                }
                else if (File.Exists(tgaPath))
                {
                    Texture.filename = tgaPath;
                    TGAToTexture(Texture, mipmaps);
                }
                else if (File.Exists(mbmPath))
                {
                    Texture.filename = mbmPath;
                    MBMToTexture(Texture, mipmaps);

                }
                tex.name = newTexture.name;
            }
        }

Usage Example

        private static TextureInfoWrapper RebuildCache(TexInfo Texture, bool compress, bool mipmaps)
        {
            Texture.loadOriginalFirst = true;
            ActiveTextureManagement.DBGLog("Loading texture...");
            TextureConverter.GetReadable(Texture, mipmaps);
            ActiveTextureManagement.DBGLog("Texture loaded.");

            TextureInfoWrapper cacheTexture = Texture.texture;
            Texture2D          tex          = cacheTexture.texture;

            String textureName = cacheTexture.name;
            String cacheFile   = KSPUtil.ApplicationRootPath + "GameData/ActiveTextureManagement/textureCache/" + textureName;

            ActiveTextureManagement.DBGLog("Rebuilding Cache... " + Texture.name);

            ActiveTextureManagement.DBGLog("Saving cache file " + cacheFile + ".imgcache");
            tex.Apply(mipmaps);
            Color32[] colors   = tex.GetPixels32();
            bool      hasAlpha = TextureConverter.WriteTo(tex, cacheFile + ".imgcache", compress);

            String originalTextureFile = Texture.filename;
            String cacheConfigFile     = cacheFile + ".tcache";

            ActiveTextureManagement.DBGLog("Created Config for" + originalTextureFile);

            String hashString = GetMD5String(originalTextureFile);

            ConfigNode config = new ConfigNode();

            config.AddValue("md5", hashString); ActiveTextureManagement.DBGLog("md5: " + hashString);
            config.AddValue("orig_format", Path.GetExtension(originalTextureFile)); ActiveTextureManagement.DBGLog("orig_format: " + Path.GetExtension(originalTextureFile));
            config.AddValue("orig_width", Texture.width.ToString()); ActiveTextureManagement.DBGLog("orig_width: " + Texture.width.ToString());
            config.AddValue("orig_height", Texture.height.ToString()); ActiveTextureManagement.DBGLog("orig_height: " + Texture.height.ToString());
            config.AddValue("is_normal", cacheTexture.isNormalMap.ToString()); ActiveTextureManagement.DBGLog("is_normal: " + cacheTexture.isNormalMap.ToString());
            config.AddValue("is_compressed", compress); ActiveTextureManagement.DBGLog("is_compressed: " + compress);
            config.AddValue("width", Texture.resizeWidth.ToString()); ActiveTextureManagement.DBGLog("width: " + Texture.resizeWidth.ToString());
            config.AddValue("height", Texture.resizeHeight.ToString()); ActiveTextureManagement.DBGLog("height: " + Texture.resizeHeight.ToString());
            config.AddValue("hasAlpha", hasAlpha); ActiveTextureManagement.DBGLog("hasAlpha: " + hasAlpha.ToString());
            config.AddValue("hasMipmaps", mipmaps); ActiveTextureManagement.DBGLog("hasMipmaps: " + hasAlpha.ToString());
            config.Save(cacheConfigFile);
            ActiveTextureManagement.DBGLog("Saved Config.");

            if (compress)
            {
                tex.Compress(true);
            }
            cacheTexture.isCompressed = compress;
            tex.Apply(false, Texture.makeNotReadable);

            cacheTexture.isReadable = !Texture.makeNotReadable;

            return(cacheTexture);
        }
All Usage Examples Of ActiveTextureManagement.TextureConverter::GetReadable