2 using System.Collections.Generic;
5 using System.Threading.Tasks;
7 using SiliconStudio.Assets.Compiler;
8 using SiliconStudio.BuildEngine;
9 using SiliconStudio.Core;
10 using SiliconStudio.Core.Diagnostics;
11 using SiliconStudio.Core.IO;
12 using SiliconStudio.Core.Serialization;
13 using SiliconStudio.Core.Serialization.Assets;
14 using SiliconStudio.Paradox.Assets.Materials;
15 using SiliconStudio.Paradox.Assets.Texture;
16 using SiliconStudio.Paradox.Graphics;
17 using SiliconStudio.Paradox.Graphics.Data;
19 namespace SiliconStudio.
Paradox.Assets
24 internal class ImageGroupCompiler<TGroupAsset, TImageInfo> :
25 AssetCompilerBase<TGroupAsset>
26 where TGroupAsset : ImageGroupAsset<TImageInfo>
27 where TImageInfo: ImageInfo
29 protected bool SeparateAlphaTexture;
31 protected Dictionary<TImageInfo, int> SpriteToTextureIndex;
33 private bool TextureFileIsValid(
UFile file)
35 return file != null && File.Exists(file);
43 SeparateAlphaTexture = context.Platform == PlatformType.Android && asset.Alpha != AlphaFormat.None && asset.Format == TextureFormat.Compressed;
46 SpriteToTextureIndex =
new Dictionary<TImageInfo, int>();
49 if (asset.Images != null)
52 var noSourceAsset = asset.Images.FirstOrDefault(x => !TextureFileIsValid(x.Source));
53 if (noSourceAsset != null)
55 result.Error(
"The texture of image '{0}' either does not exist or is invalid", noSourceAsset.Name);
60 var spriteByTextures = asset.Images.GroupBy(x => x.Source).ToArray();
61 for (
int i = 0; i < spriteByTextures.Length; i++)
63 var spriteAssetArray = spriteByTextures[i].ToArray();
64 foreach (var spriteAsset
in spriteAssetArray)
65 SpriteToTextureIndex[spriteAsset] = i;
72 Format = asset.Format,
73 GenerateMipmaps = asset.GenerateMipmaps,
75 ColorKeyColor = asset.ColorKeyColor,
76 ColorKeyEnabled = asset.ColorKeyEnabled,
80 var assetDirectory = assetAbsolutePath.GetParent();
81 var assetSource = UPath.Combine(assetDirectory, spriteAssetArray[0]
.Source);
84 result.BuildSteps.Add(
85 new TextureAssetCompiler.TextureConvertCommand(
86 ImageGroupAsset.BuildTextureUrl(urlInStorage, i),
87 new TextureConvertParameters(assetSource, textureAsset, context.
Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality(), SeparateAlphaTexture)));
98 public class ImageGroupCommand<TGroupAsset, TImageInfo, TImageGroupData, TImageData> :
AssetCommand<ImageGroupParameters<TGroupAsset>>
101 where TImageGroupData : ImageGroupData<TImageData>, new()
108 protected ImageGroupCommand(
string url, ImageGroupParameters<TGroupAsset> asset, Dictionary<TImageInfo, int> imageToTextureIndex,
bool useSeparateAlphaTexture)
111 ImageToTextureIndex = imageToTextureIndex;
112 UseSeparateAlphaTexture = useSeparateAlphaTexture;
117 for (
int i = 0; i < ImageToTextureIndex.Values.Distinct().Count(); i++)
119 if (UseSeparateAlphaTexture)
121 var textureUrl = ImageGroupAsset.BuildTextureUrl(Url, i);
135 var imageGroupData =
new TImageGroupData { Images =
new List<TImageData>() };
138 foreach (var uiImage
in asset.GroupAsset.Images)
140 var newImage =
new TImageData
143 Region = uiImage.TextureRegion,
144 IsTransparent = asset.GroupAsset.Alpha != AlphaFormat.None,
148 if (UseSeparateAlphaTexture)
150 var baseLocation = ImageGroupAsset.BuildTextureUrl(Url, ImageToTextureIndex[uiImage]);
151 newImage.Texture =
new ContentReference<Texture2D> { Location = TextureAlphaComponentSplitter.GenerateColorTextureURL(baseLocation) };
152 newImage.TextureAlpha =
new ContentReference<Texture2D> { Location = TextureAlphaComponentSplitter.GenerateAlphaTextureURL(baseLocation) };
156 newImage.Texture =
new ContentReference<Texture2D> { Location = ImageGroupAsset.BuildTextureUrl(Url, ImageToTextureIndex[uiImage]) };
159 SetImageSpecificFields(uiImage, newImage);
161 imageGroupData.Images.Add(newImage);
165 assetManager.Save(Url, imageGroupData);
167 return Task.FromResult(ResultStatus.Successful);
179 public class ImageGroupParameters<T>
187 GroupAsset = groupAsset;
PlatformType Platform
Gets or sets the target platform for compiler is being used for.
Result of a compilation of assets when using IAssetCompiler.Compile
PlatformType
Describes the platform operating system.
static string GenerateColorTextureURL(UFile originalLocation)
virtual void SetImageSpecificFields(TImageInfo imageInfo, TImageData newImage)
Utility class to split this material texture containing alpha into two texture materials: one contain...
static string GenerateAlphaTextureURL(UFile originalLocation)
static string BuildTextureUrl(UFile textureAbsolutePath, int spriteIndex)
A command processing an Asset.
readonly Dictionary< TImageInfo, int > ImageToTextureIndex
The context used when compiling an asset in a Package.
When embedded in a EnumerableBuildStep, this build step will force all previous computations to be fi...
override Task< ResultStatus > DoCommandOverride(ICommandContext commandContext)
ImageGroupCommand(string url, ImageGroupParameters< TGroupAsset > asset, Dictionary< TImageInfo, int > imageToTextureIndex, bool useSeparateAlphaTexture)
readonly bool UseSeparateAlphaTexture
Allow data to be stored in the alpha component.
Describes a texture asset.
Parameters used for converting/processing the texture in the storage.
override IEnumerable< ObjectUrl > GetInputFiles()
Describes various information about an image.
Data type for SiliconStudio.Paradox.Graphics.ImageFragment.
Android.Widget.Orientation Orientation
ImageGroupParameters(T groupAsset, PlatformType platform)
HRESULT PremultiplyAlpha(_In_ const Image &srcImage, _In_ DWORD flags, _Out_ ScratchImage &image)
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Describes an image group asset.