public override IEnumerable <AssetItem> Import(UFile rawAssetPath, AssetImporterParameters importParameters) { var asset = new TextureAsset { Source = rawAssetPath }; // Creates the url to the texture var textureUrl = new UFile(rawAssetPath.GetFileName(), null); yield return(new AssetItem(textureUrl, asset)); }
public TextureConvertParameters( UFile sourcePathFromDisk, TextureAsset texture, PlatformType platform, GraphicsPlatform graphicsPlatform, GraphicsProfile graphicsProfile, TextureQuality textureQuality, bool separateAlpha) { SourcePathFromDisk = sourcePathFromDisk; Texture = texture; Platform = platform; GraphicsPlatform = graphicsPlatform; GraphicsProfile = graphicsProfile; TextureQuality = textureQuality; SeparateAlpha = separateAlpha; }
public static ResultStatus ImportAndSaveTextureImage(UFile sourcePath, string outputUrl, TextureAsset textureAsset, TextureConvertParameters parameters, bool separateAlpha, CancellationToken cancellationToken, Logger logger) { var assetManager = new AssetManager(); using (var texTool = new TextureTool()) using (var texImage = texTool.Load(sourcePath)) { // Apply transformations texTool.Decompress(texImage); if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } // Resize the image if (textureAsset.IsSizeInPercentage) { texTool.Rescale(texImage, textureAsset.Width / 100.0f, textureAsset.Height / 100.0f, Filter.Rescaling.Lanczos3); } else { texTool.Resize(texImage, (int)textureAsset.Width, (int)textureAsset.Height, Filter.Rescaling.Lanczos3); } if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } // texture size is now determined, we can cache it var textureSize = new Int2(texImage.Width, texImage.Height); // Check that the resulting texture size is supported by the targeted graphics profile if (!TextureSizeSupported(textureAsset.Format, parameters.GraphicsPlatform, parameters.GraphicsProfile, textureSize, textureAsset.GenerateMipmaps, logger)) { return(ResultStatus.Failed); } // Apply the color key if (textureAsset.ColorKeyEnabled) { texTool.ColorKey(texImage, textureAsset.ColorKeyColor); } if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } // Pre-multiply alpha if (textureAsset.PremultiplyAlpha) { texTool.PreMultiplyAlpha(texImage); } if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } // Generate mipmaps if (textureAsset.GenerateMipmaps) { texTool.GenerateMipMaps(texImage, Filter.MipMapGeneration.Box); } if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } // Convert/Compress to output format // TODO: Change alphaFormat depending on actual image content (auto-detection)? var outputFormat = DetermineOutputFormat(textureAsset.Format, textureAsset.Alpha, parameters.Platform, parameters.GraphicsPlatform, textureSize, texImage.Format); texTool.Compress(texImage, outputFormat, (TextureConverter.Requests.TextureQuality)parameters.TextureQuality); if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } // Save the texture if (separateAlpha) { TextureAlphaComponentSplitter.CreateAndSaveSeparateTextures(texTool, texImage, outputUrl, textureAsset.GenerateMipmaps); } else { using (var outputImage = texTool.ConvertToParadoxImage(texImage)) { if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } assetManager.Save(outputUrl, outputImage); logger.Info("Compression successful [{3}] to ({0}x{1},{2})", outputImage.Description.Width, outputImage.Description.Height, outputImage.Description.Format, outputUrl); } } } return(ResultStatus.Successful); }