public override IEnumerable <ObjectUrl> GetInputFiles() { for (int i = 0; i < ImageToTextureIndex.Values.Distinct().Count(); i++) { yield return(new ObjectUrl(UrlType.Internal, ImageGroupAsset.BuildTextureUrl(Url, i))); } }
protected Dictionary <TImageInfo, int> CompileGroup(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, TGroupAsset asset, AssetCompilerResult result) { result.BuildSteps = new AssetBuildStep(AssetItem); // Evaluate if we need to use a separate the alpha texture SeparateAlphaTexture = TextureCommandHelper.ShouldSeparateAlpha(asset.Alpha, asset.Format, context.Platform, context.GetGraphicsProfile()); // create the registry containing the sprite assets texture index association var imageToTextureIndex = new Dictionary <TImageInfo, int>(); // create and add import texture commands if (asset.Images != null) { // sort sprites by referenced texture. var spriteByTextures = asset.Images.GroupBy(x => x.Source).ToArray(); for (int i = 0; i < spriteByTextures.Length; i++) { // skip the texture if the file is not valid. var textureFile = spriteByTextures[i].Key; if (!TextureFileIsValid(textureFile)) { continue; } var spriteAssetArray = spriteByTextures[i].ToArray(); foreach (var spriteAsset in spriteAssetArray) { imageToTextureIndex[spriteAsset] = i; } // create an texture asset. var textureAsset = new TextureAsset { Id = Guid.Empty, // CAUTION: It is important to use an empty GUID here, as we don't want the command to be rebuilt (by default, a new asset is creating a new guid) Alpha = asset.Alpha, Format = asset.Format, GenerateMipmaps = asset.GenerateMipmaps, PremultiplyAlpha = asset.PremultiplyAlpha, ColorKeyColor = asset.ColorKeyColor, ColorKeyEnabled = asset.ColorKeyEnabled, }; // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, spriteAssetArray[0].Source); // add the texture build command. result.BuildSteps.Add( new TextureAssetCompiler.TextureConvertCommand( ImageGroupAsset.BuildTextureUrl(urlInStorage, i), new TextureConvertParameters(assetSource, textureAsset, context.Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality(), SeparateAlphaTexture))); } result.BuildSteps.Add(new WaitBuildStep()); // wait the textures to be imported } return(imageToTextureIndex); }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, TGroupAsset asset, AssetCompilerResult result) { result.BuildSteps = new ListBuildStep(); // Evaluate if we need to use a separate the alpha texture SeparateAlphaTexture = context.Platform == PlatformType.Android && asset.Alpha != AlphaFormat.None && asset.Format == TextureFormat.Compressed; // create the registry containing the sprite assets texture index association SpriteToTextureIndex = new Dictionary <TImageInfo, int>(); // create and add import texture commands if (asset.Images != null) { // return compilation error if one or more of the sprite does not have a valid texture var noSourceAsset = asset.Images.FirstOrDefault(x => !TextureFileIsValid(x.Source)); if (noSourceAsset != null) { result.Error("The texture of image '{0}' either does not exist or is invalid", noSourceAsset.Name); return; } // sort sprites by referenced texture. var spriteByTextures = asset.Images.GroupBy(x => x.Source).ToArray(); for (int i = 0; i < spriteByTextures.Length; i++) { var spriteAssetArray = spriteByTextures[i].ToArray(); foreach (var spriteAsset in spriteAssetArray) { SpriteToTextureIndex[spriteAsset] = i; } // create an texture asset. var textureAsset = new TextureAsset { Id = Guid.Empty, // CAUTION: It is important to use an empty GUID here, as we don't want the command to be rebuilt (by default, a new asset is creating a new guid) Alpha = asset.Alpha, Format = asset.Format, GenerateMipmaps = asset.GenerateMipmaps, PremultiplyAlpha = asset.PremultiplyAlpha, ColorKeyColor = asset.ColorKeyColor, ColorKeyEnabled = asset.ColorKeyEnabled, }; // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, spriteAssetArray[0].Source); // add the texture build command. result.BuildSteps.Add( new TextureAssetCompiler.TextureConvertCommand( ImageGroupAsset.BuildTextureUrl(urlInStorage, i), new TextureConvertParameters(assetSource, textureAsset, context.Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality(), SeparateAlphaTexture))); } result.BuildSteps.Add(new WaitBuildStep()); // wait the textures to be imported } }
public override IEnumerable <ObjectUrl> GetInputFiles() { for (int i = 0; i < ImageToTextureIndex.Values.Distinct().Count(); i++) { if (UseSeparateAlphaTexture) { //var textureUrl = ImageGroupAsset.BuildTextureUrl(Url, i); //yield return new ObjectUrl(UrlType.Internal, TextureAlphaComponentSplitter.GenerateColorTextureURL(textureUrl)); //yield return new ObjectUrl(UrlType.Internal, TextureAlphaComponentSplitter.GenerateAlphaTextureURL(textureUrl)); } else { yield return(new ObjectUrl(UrlType.Internal, ImageGroupAsset.BuildTextureUrl(Url, i))); } } }
protected override Task <ResultStatus> DoCommandOverride(ICommandContext commandContext) { var assetManager = new AssetManager(); var imageGroupData = new TImageGroupData { Images = new List <TImageData>() }; // add the sprite data to the sprite list. foreach (var uiImage in asset.GroupAsset.Images) { var newImage = new TImageData { Name = uiImage.Name, Region = uiImage.TextureRegion, IsTransparent = asset.GroupAsset.Alpha != AlphaFormat.None, // todo analyze texture region texture data to auto-determine alpha? Orientation = uiImage.Orientation, }; if (UseSeparateAlphaTexture) { var baseLocation = ImageGroupAsset.BuildTextureUrl(Url, ImageToTextureIndex[uiImage]); newImage.Texture = new ContentReference <Graphics.Texture> { Location = TextureAlphaComponentSplitter.GenerateColorTextureURL(baseLocation) }; newImage.TextureAlpha = new ContentReference <Graphics.Texture> { Location = TextureAlphaComponentSplitter.GenerateAlphaTextureURL(baseLocation) }; } else { newImage.Texture = new ContentReference <Graphics.Texture> { Location = ImageGroupAsset.BuildTextureUrl(Url, ImageToTextureIndex[uiImage]) }; } SetImageSpecificFields(uiImage, newImage); imageGroupData.Images.Add(newImage); } // save the imageData into the data base assetManager.Save(Url, imageGroupData); return(Task.FromResult(ResultStatus.Successful)); }
protected override Task <ResultStatus> DoCommandOverride(ICommandContext commandContext) { var assetManager = new AssetManager(); var imageGroupData = new TImageGroupData { Images = new List <TImageData>() }; // add the sprite data to the sprite list. foreach (var uiImage in asset.GroupAsset.Images) { var newImage = new TImageData { Name = uiImage.Name, Region = uiImage.TextureRegion, IsTransparent = asset.GroupAsset.Alpha != AlphaFormat.None, // todo analyze texture region texture data to auto-determine alpha? Orientation = uiImage.Orientation, }; if (UseSeparateAlphaTexture) { //var baseLocation = ImageGroupAsset.BuildTextureUrl(Url, ImageToTextureIndex[uiImage]); // newImage.Texture = AttachedReferenceManager.CreateSerializableVersion<Texture>(Guid.Empty, TextureAlphaComponentSplitter.GenerateColorTextureURL(baseLocation)); // newImage.TextureAlpha = AttachedReferenceManager.CreateSerializableVersion<Texture>(Guid.Empty, TextureAlphaComponentSplitter.GenerateAlphaTextureURL(baseLocation)); } else { int imageIndex; if (ImageToTextureIndex.TryGetValue(uiImage, out imageIndex)) { newImage.Texture = AttachedReferenceManager.CreateSerializableVersion <Texture>(Guid.Empty, ImageGroupAsset.BuildTextureUrl(Url, ImageToTextureIndex[uiImage])); } else { commandContext.Logger.Warning("Image '{0}' has an invalid image source file '{1}', resulting texture will be null.", uiImage.Name, uiImage.Source); } } SetImageSpecificFields(uiImage, newImage); imageGroupData.Images.Add(newImage); } // save the imageData into the data base assetManager.Save(Url, imageGroupData); return(Task.FromResult(ResultStatus.Successful)); }