Exemplo n.º 1
0
        public static void CreateAndSaveSeparateTextures(TextureTool texTool, TexImage texImage, string originalTextureURL, bool shouldGenerateMipMaps, PixelFormat outputFormat = PixelFormat.ETC1)
        {
            var assetManager = new AssetManager();
            var alphaTextureURL = GenerateAlphaTextureURL(originalTextureURL);
            var colorTextureURL = GenerateColorTextureURL(originalTextureURL);

            // create a new image containing only the alpha component
            texTool.Decompress(texImage, texImage.Format.IsSRgb());
            using (var alphaImage = texTool.CreateImageFromAlphaComponent(texImage))
            {
                // generate the mip-maps for the alpha component if required
                if (shouldGenerateMipMaps)
                    texTool.GenerateMipMaps(alphaImage, Filter.MipMapGeneration.Box);

                // save the alpha component
                texTool.Compress(alphaImage, outputFormat);
                using (var outputImage = texTool.ConvertToXenkoImage(alphaImage))
                    assetManager.Save(alphaTextureURL, outputImage.ToSerializableVersion());
            }

            // save the color component
            texTool.Decompress(texImage, texImage.Format.IsSRgb());
            texTool.Compress(texImage, outputFormat);
            using (var outputImage = texTool.ConvertToXenkoImage(texImage))
                assetManager.Save(colorTextureURL, outputImage.ToSerializableVersion());
        }