protected override IEnumerable <ObjectUrl> GetInputFilesImpl() { // Add game settings asset URL yield return(new ObjectUrl(UrlType.Content, GameSettingsAsset.GameSettingsLocation)); var gameSettings = context.GetGameSettingsAsset(); var defaultSceneUrl = gameSettings.DefaultScene != null?AttachedReferenceManager.GetUrl(gameSettings.DefaultScene) : null; if (defaultSceneUrl == null) { yield break; } // Add scene yield return(new ObjectUrl(UrlType.Content, defaultSceneUrl)); // And all its dependencies (TODO: restrict ourselves on what affect rendering?) var sceneAssetItem = package.Session.FindAsset(defaultSceneUrl); var dependencies = package.Session.DependencyManager.ComputeDependencies(sceneAssetItem.Id, AssetDependencySearchOptions.Out | AssetDependencySearchOptions.Recursive, ContentLinkType.Reference); foreach (var dependency in dependencies.LinksOut) { yield return(new ObjectUrl(UrlType.Content, dependency.Item.Location)); } }
/// <inheritdoc/> public override Task <ResultStatus> Execute(IExecuteContext executeContext, BuilderContext builderContext) { var steps = new List <BuildStep>(); var urlRoot = originalSourcePath.GetParent(); var fileStream = new FileStream(originalSourcePath.ToWindowsPath(), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); using (var recordedEffectCompile = new EffectLogStore(fileStream)) { recordedEffectCompile.LoadNewValues(); foreach (var entry in recordedEffectCompile.GetValues()) { var effectCompileRequest = entry.Key; var compilerParameters = new CompilerParameters(); effectCompileRequest.UsedParameters.CopyTo(compilerParameters); compilerParameters.Platform = context.GetGraphicsPlatform(); compilerParameters.Profile = context.GetGameSettingsAsset().DefaultGraphicsProfile; steps.Add(new CommandBuildStep(new EffectCompileCommand(context, urlRoot, effectCompileRequest.EffectName, compilerParameters, package))); } } Steps = steps; return(base.Execute(executeContext, builderContext)); }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, SpriteSheetAsset asset, AssetCompilerResult result) { result.BuildSteps = new AssetBuildStep(AssetItem); // create the registry containing the sprite assets texture index association var imageToTextureIndex = new Dictionary <SpriteInfo, int>(); // create and add import texture commands if (asset.Sprites != null) { var gameSettingsAsset = context.GetGameSettingsAsset(); // sort sprites by referenced texture. var spriteByTextures = asset.Sprites.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( SpriteSheetAsset.BuildTextureUrl(urlInStorage, i), new TextureConvertParameters(assetSource, textureAsset, context.Platform, context.GetGraphicsPlatform(), gameSettingsAsset.DefaultGraphicsProfile, gameSettingsAsset.TextureQuality))); } result.BuildSteps.Add(new WaitBuildStep()); // wait the textures to be imported } if (!result.HasErrors) { result.BuildSteps.Add(new SpriteSheetCommand(urlInStorage, new SpriteSheetParameters(asset, context.Platform), imageToTextureIndex)); } }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, SkyboxAsset asset, AssetCompilerResult result) { result.BuildSteps = new AssetBuildStep(AssetItem); result.ShouldWaitForPreviousBuilds = true; // build the textures for windows (needed for skybox compilation) foreach (var dependency in asset.Model.GetDependencies()) { var assetItem = context.Package.Assets.Find(dependency.Id); if (assetItem != null && assetItem.Asset is TextureAsset) { var textureAsset = (TextureAsset)assetItem.Asset; // Get absolute path of asset source on disk var assetSource = GetAbsolutePath(assetItem.Location.GetDirectoryAndFileName(), textureAsset.Source); // Create a synthetic url var textureUrl = SkyboxGenerator.BuildTextureForSkyboxGenerationLocation(assetItem.Location); var gameSettingsAsset = context.GetGameSettingsAsset(); // Create and add the texture command. var textureParameters = new TextureConvertParameters(assetSource, textureAsset, PlatformType.Windows, GraphicsPlatform.Direct3D11, GraphicsProfile.Level_10_0, gameSettingsAsset.TextureQuality); result.BuildSteps.Add(new AssetBuildStep(AssetItem) { new TextureAssetCompiler.TextureConvertCommand(textureUrl, textureParameters) }); } } // add the skybox command itself. result.BuildSteps.Add(new WaitBuildStep()); result.BuildSteps.Add(new SkyboxCompileCommand(urlInStorage, asset)); }
private void GraphicsDeviceManagerDeviceCreated(object sender, EventArgs e) { // Transmit actual GraphicsProfile to preview and thumbnail builder context var graphicsProfile = PreviewGame.GraphicsDeviceManager.GraphicsDevice.Features.CurrentProfile; //ThumbnailService.ThumbnailBuilderContext.GetGameSettingsAsset().Get<RenderingSettings>().DefaultGraphicsProfile = graphicsProfile; previewCompileContext.GetGameSettingsAsset().GetOrCreate <RenderingSettings>().DefaultGraphicsProfile = graphicsProfile; }
protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result) { var asset = (PrefabModelAsset)assetItem.Asset; var renderingSettings = context.GetGameSettingsAsset().GetOrCreate <RenderingSettings>(); result.BuildSteps = new AssetBuildStep(assetItem); result.BuildSteps.Add(new PrefabModelAssetCompileCommand(targetUrlInStorage, asset, assetItem, renderingSettings)); }
protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result) { var asset = (ModelAsset)assetItem.Asset; // Get absolute path of asset source on disk var assetDirectory = assetItem.FullPath.GetParent(); var assetSource = UPath.Combine(assetDirectory, asset.Source); var gameSettingsAsset = context.GetGameSettingsAsset(); var renderingSettings = gameSettingsAsset.GetOrCreate <RenderingSettings>(); var allow32BitIndex = true; var maxInputSlots = 32; var allowUnsignedBlendIndices = true; var extension = asset.Source.GetFileExtension(); // Find skeleton asset, if any AssetItem skeleton = null; if (asset.Skeleton != null) { skeleton = assetItem.Package.FindAssetFromProxyObject(asset.Skeleton); } var importModelCommand = ImportModelCommand.Create(extension); if (importModelCommand is null) { result.Error($"No importer found for model extension '{extension}'. The model '{assetSource}' can't be imported."); return; } importModelCommand.InputFilesGetter = () => GetInputFiles(assetItem); importModelCommand.Mode = ImportModelCommand.ExportMode.Model; importModelCommand.SourcePath = assetSource; importModelCommand.Location = targetUrlInStorage; importModelCommand.Allow32BitIndex = allow32BitIndex; importModelCommand.MaxInputSlots = maxInputSlots; importModelCommand.AllowUnsignedBlendIndices = allowUnsignedBlendIndices; importModelCommand.Materials = asset.Materials; importModelCommand.ScaleImport = asset.ScaleImport; importModelCommand.PivotPosition = asset.PivotPosition; importModelCommand.MergeMeshes = asset.MergeMeshes; importModelCommand.DeduplicateMaterials = asset.DeduplicateMaterials; importModelCommand.ModelModifiers = asset.Modifiers; if (skeleton != null) { importModelCommand.SkeletonUrl = skeleton.Location; // NOTE: Skeleton override values importModelCommand.ScaleImport = ((SkeletonAsset)skeleton.Asset).ScaleImport; importModelCommand.PivotPosition = ((SkeletonAsset)skeleton.Asset).PivotPosition; } importModelCommand.Package = assetItem.Package; result.BuildSteps = new AssetBuildStep(assetItem); result.BuildSteps.Add(importModelCommand); }
public NavmeshBuildCommand(string url, AssetItem assetItem, NavigationMeshAsset value, AssetCompilerContext context) : base(url, value, assetItem.Package) { gameSettingsAsset = context.GetGameSettingsAsset(); asset = value; assetUrl = url; Version = 1; // Removed separate debug model stored in the navigation mesh }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, PrefabModelAsset asset, AssetCompilerResult result) { var renderingSettings = context.GetGameSettingsAsset().Get <RenderingSettings>(); result.BuildSteps = new ListBuildStep { new PrefabModelAssetCompileCommand(urlInStorage, asset, AssetItem, renderingSettings) }; result.ShouldWaitForPreviousBuilds = true; }
public static BuildStep FromRequest(AssetCompilerContext context, Package package, UDirectory urlRoot, EffectCompileRequest effectCompileRequest) { var compilerParameters = new CompilerParameters(effectCompileRequest.UsedParameters); compilerParameters.EffectParameters.Platform = context.GetGraphicsPlatform(package); compilerParameters.EffectParameters.Profile = context.GetGameSettingsAsset().Get <RenderingSettings>(context.Platform).DefaultGraphicsProfile; compilerParameters.EffectParameters.ApplyCompilationMode(context.GetCompilationMode()); return(new CommandBuildStep(new EffectCompileCommand(context, urlRoot, effectCompileRequest.EffectName, compilerParameters, package))); }
public MaterialCompileCommand(string url, AssetItem assetItem, MaterialAsset value, AssetCompilerContext context) : base(url, value, assetItem.Package) { Version = 4; this.assetItem = assetItem; colorSpace = context.GetColorSpace(); assetUrl = new UFile(url); graphicsProfile = context.GetGameSettingsAsset().GetOrCreate <RenderingSettings>(context.Platform).DefaultGraphicsProfile; }
protected override void Compile(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result) { var asset = (PrefabModelAsset)assetItem.Asset; var renderingSettings = context.GetGameSettingsAsset().Get <RenderingSettings>(); result.BuildSteps = new ListBuildStep { new PrefabModelAssetCompileCommand(targetUrlInStorage, asset, assetItem, renderingSettings) }; result.ShouldWaitForPreviousBuilds = true; }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, ModelAsset asset, AssetCompilerResult result) { if (!EnsureSourceExists(result, asset, assetAbsolutePath)) { return; } // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, asset.Source); var gameSettingsAsset = context.GetGameSettingsAsset(); var allow32BitIndex = gameSettingsAsset.DefaultGraphicsProfile >= GraphicsProfile.Level_9_2; var allowUnsignedBlendIndices = context.GetGraphicsPlatform() != GraphicsPlatform.OpenGLES; var extension = asset.Source.GetFileExtension(); if (ImportFbxCommand.IsSupportingExtensions(extension)) { result.BuildSteps = new AssetBuildStep(AssetItem) { new ImportFbxCommand { SourcePath = assetSource, Location = urlInStorage, Allow32BitIndex = allow32BitIndex, AllowUnsignedBlendIndices = allowUnsignedBlendIndices, Compact = asset.Compact, PreservedNodes = asset.PreservedNodes, Materials = asset.Materials, ScaleImport = asset.ScaleImport, }, }; } else if (ImportAssimpCommand.IsSupportingExtensions(extension)) { result.BuildSteps = new AssetBuildStep(AssetItem) { new ImportAssimpCommand { SourcePath = assetSource, Location = urlInStorage, Allow32BitIndex = allow32BitIndex, AllowUnsignedBlendIndices = allowUnsignedBlendIndices, Compact = asset.Compact, PreservedNodes = asset.PreservedNodes, Materials = asset.Materials, ScaleImport = asset.ScaleImport, }, }; } else { result.Error("No importer found for model extension '{0}. The model '{1}' can't be imported.", extension, assetSource); } }
public static IGameSettingsProfile GetGameSettingsForCurrentProfile(this AssetCompilerContext context) { var gameSettings = context.GetGameSettingsAsset(); IGameSettingsProfile gameSettingsProfile = null; if (gameSettings != null && gameSettings.Profiles != null) { gameSettings.Profiles.TryGetValue(context.Profile, out gameSettingsProfile); } // TODO: Return default game settings profile based on the platform return(gameSettingsProfile); }
protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result) { var asset = (TextureAsset)assetItem.Asset; // Get absolute path of asset source on disk var assetSource = GetAbsolutePath(assetItem, asset.Source); var gameSettingsAsset = context.GetGameSettingsAsset(); var colorSpace = context.GetColorSpace(); var parameter = new TextureConvertParameters(assetSource, asset, context.Platform, context.GetGraphicsPlatform(assetItem.Package), gameSettingsAsset.GetOrCreate<RenderingSettings>(context.Platform).DefaultGraphicsProfile, gameSettingsAsset.GetOrCreate<TextureSettings>().TextureQuality, colorSpace); result.BuildSteps = new AssetBuildStep(assetItem); result.BuildSteps.Add(new TextureConvertCommand(targetUrlInStorage, parameter, assetItem.Package)); }
protected override void Compile(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result) { var asset = (SpriteStudioModelAsset)assetItem.Asset; var gameSettingsAsset = context.GetGameSettingsAsset(); var renderingSettings = gameSettingsAsset.Get <RenderingSettings>(context.Platform); var colorSpace = renderingSettings.ColorSpace; var cells = new List <SpriteStudioCell>(); var images = new List <UFile>(); if (!SpriteStudioXmlImport.ParseCellMaps(asset.Source, images, cells)) { throw new Exception("Failed to parse Sprite Studio cell textures."); } var texIndex = 0; asset.BuildTextures.Clear(); foreach (var texture in images) { 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 = AlphaFormat.Auto, Format = TextureFormat.Color32Bits, GenerateMipmaps = true, PremultiplyAlpha = true, ColorSpace = TextureColorSpace.Auto, Hint = TextureHint.Color }; result.BuildSteps.Add( new TextureAssetCompiler.TextureConvertCommand( targetUrlInStorage + texIndex, new TextureConvertParameters(texture, textureAsset, context.Platform, context.GetGraphicsPlatform(assetItem.Package), renderingSettings.DefaultGraphicsProfile, gameSettingsAsset.Get <TextureSettings>().TextureQuality, colorSpace))); asset.BuildTextures.Add(targetUrlInStorage + texIndex); texIndex++; } result.BuildSteps.Add(new AssetBuildStep(assetItem) { new SpriteStudioModelAssetCommand(targetUrlInStorage, asset, colorSpace) }); }
protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result) { var asset = (SpriteStudioModelAsset)assetItem.Asset; var gameSettingsAsset = context.GetGameSettingsAsset(); var renderingSettings = gameSettingsAsset.GetOrCreate <RenderingSettings>(context.Platform); var colorSpace = renderingSettings.ColorSpace; var cells = new List <SpriteStudioCell>(); var images = new List <UFile>(); if (!SpriteStudioXmlImport.ParseCellMaps(asset.Source, images, cells)) { throw new Exception("Failed to parse SpriteStudio cell textures."); } var texIndex = 0; asset.BuildTextures.Clear(); foreach (var texture in images) { var textureAsset = new TextureAsset { Id = AssetId.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) IsStreamable = false, IsCompressed = false, GenerateMipmaps = true, Type = new ColorTextureType { Alpha = AlphaFormat.Auto, PremultiplyAlpha = true, UseSRgbSampling = true, } }; var textureConvertParameters = new TextureConvertParameters(texture, textureAsset, context.Platform, context.GetGraphicsPlatform(assetItem.Package), renderingSettings.DefaultGraphicsProfile, gameSettingsAsset.GetOrCreate <TextureSettings>().TextureQuality, colorSpace); var textureConvertCommand = new TextureAssetCompiler.TextureConvertCommand(targetUrlInStorage + texIndex, textureConvertParameters, assetItem.Package); result.BuildSteps.Add(textureConvertCommand); asset.BuildTextures.Add(targetUrlInStorage + texIndex); texIndex++; } var step = new AssetBuildStep(assetItem); step.Add(new SpriteStudioModelAssetCommand(targetUrlInStorage, asset, colorSpace, assetItem.Package)); result.BuildSteps.Add(step); }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, ModelAsset asset, AssetCompilerResult result) { if (!EnsureSourcesExist(result, asset, assetAbsolutePath)) { return; } // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, asset.Source); var gameSettingsAsset = context.GetGameSettingsAsset(); var renderingSettings = gameSettingsAsset.Get <RenderingSettings>(); var allow32BitIndex = renderingSettings.DefaultGraphicsProfile >= GraphicsProfile.Level_9_2; var allowUnsignedBlendIndices = context.GetGraphicsPlatform(AssetItem.Package) != GraphicsPlatform.OpenGLES; var extension = asset.Source.GetFileExtension(); // Find skeleton asset, if any AssetItem skeleton = null; if (asset.Skeleton != null) { skeleton = AssetItem.Package.FindAssetFromAttachedReference(asset.Skeleton); } var importModelCommand = ImportModelCommand.Create(extension); if (importModelCommand == null) { result.Error("No importer found for model extension '{0}. The model '{1}' can't be imported.", extension, assetSource); return; } importModelCommand.Mode = ImportModelCommand.ExportMode.Model; importModelCommand.SourcePath = assetSource; importModelCommand.Location = urlInStorage; importModelCommand.Allow32BitIndex = allow32BitIndex; importModelCommand.AllowUnsignedBlendIndices = allowUnsignedBlendIndices; importModelCommand.Materials = asset.Materials; importModelCommand.ScaleImport = asset.ScaleImport; importModelCommand.PivotPosition = asset.PivotPosition; importModelCommand.SkeletonUrl = skeleton?.Location; result.BuildSteps = new AssetBuildStep(AssetItem) { importModelCommand }; }
protected override void Compile(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result) { var asset = (ModelAsset)assetItem.Asset; // Get absolute path of asset source on disk var assetDirectory = assetItem.FullPath.GetParent(); var assetSource = UPath.Combine(assetDirectory, asset.Source); var gameSettingsAsset = context.GetGameSettingsAsset(); var renderingSettings = gameSettingsAsset.Get <RenderingSettings>(); var allow32BitIndex = renderingSettings.DefaultGraphicsProfile >= GraphicsProfile.Level_9_2; var maxInputSlots = renderingSettings.DefaultGraphicsProfile >= GraphicsProfile.Level_10_1 ? 32 : 16; var allowUnsignedBlendIndices = context.GetGraphicsPlatform(assetItem.Package) != GraphicsPlatform.OpenGLES; var extension = asset.Source.GetFileExtension(); // Find skeleton asset, if any AssetItem skeleton = null; if (asset.Skeleton != null) { skeleton = assetItem.Package.FindAssetFromProxyObject(asset.Skeleton); } var importModelCommand = ImportModelCommand.Create(extension); if (importModelCommand == null) { result.Error($"No importer found for model extension '{extension}. The model '{assetSource}' can't be imported."); return; } importModelCommand.Mode = ImportModelCommand.ExportMode.Model; importModelCommand.SourcePath = assetSource; importModelCommand.Location = targetUrlInStorage; importModelCommand.Allow32BitIndex = allow32BitIndex; importModelCommand.MaxInputSlots = maxInputSlots; importModelCommand.AllowUnsignedBlendIndices = allowUnsignedBlendIndices; importModelCommand.Materials = asset.Materials; importModelCommand.ScaleImport = asset.ScaleImport; importModelCommand.PivotPosition = asset.PivotPosition; importModelCommand.SkeletonUrl = skeleton?.Location; result.BuildSteps = new AssetBuildStep(assetItem) { importModelCommand }; }
protected override void Compile(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result) { var asset = (SkyboxAsset)assetItem.Asset; result.BuildSteps = new ListBuildStep(); result.ShouldWaitForPreviousBuilds = true; var colorSpace = context.GetColorSpace(); // build the textures for windows (needed for skybox compilation) foreach (var dependency in asset.Model.GetDependencies()) { var dependencyItem = assetItem.Package.Assets.Find(dependency.Id); if (dependencyItem?.Asset is TextureAsset) { var textureAsset = (TextureAsset)dependencyItem.Asset; // Get absolute path of asset source on disk var assetSource = GetAbsolutePath(dependencyItem, textureAsset.Source); // Create a synthetic url var textureUrl = SkyboxGenerator.BuildTextureForSkyboxGenerationLocation(dependencyItem.Location); var gameSettingsAsset = context.GetGameSettingsAsset(); var renderingSettings = gameSettingsAsset.Get <RenderingSettings>(context.Platform); // Select the best graphics profile var graphicsProfile = renderingSettings.DefaultGraphicsProfile >= GraphicsProfile.Level_10_0 ? renderingSettings.DefaultGraphicsProfile : GraphicsProfile.Level_10_0; var textureAssetItem = new AssetItem(textureUrl, textureAsset); // Create and add the texture command. var textureParameters = new TextureConvertParameters(assetSource, textureAsset, PlatformType.Windows, GraphicsPlatform.Direct3D11, graphicsProfile, gameSettingsAsset.Get <TextureSettings>().TextureQuality, colorSpace); result.BuildSteps.Add(new AssetBuildStep(textureAssetItem) { new TextureAssetCompiler.TextureConvertCommand(textureUrl, textureParameters) }); } } // add the skybox command itself. result.BuildSteps.Add(new AssetBuildStep(assetItem) { new SkyboxCompileCommand(targetUrlInStorage, asset) }); }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, TextureAsset asset, AssetCompilerResult result) { if (!EnsureSourceExists(result, asset, assetAbsolutePath)) { return; } // Get absolute path of asset source on disk var assetSource = GetAbsolutePath(assetAbsolutePath, asset.Source); var gameSettingsAsset = context.GetGameSettingsAsset(); var parameter = new TextureConvertParameters(assetSource, asset, context.Platform, context.GetGraphicsPlatform(), gameSettingsAsset.DefaultGraphicsProfile, gameSettingsAsset.TextureQuality); result.BuildSteps = new AssetBuildStep(AssetItem) { new TextureConvertCommand(urlInStorage, parameter) }; }
public static ColorSpace GetColorSpace(this AssetCompilerContext context) { var settings = context.GetGameSettingsAsset().GetOrCreate <RenderingSettings>(context.Platform); return(settings.ColorSpace); }
protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result) { var asset = (SpriteSheetAsset)assetItem.Asset; var gameSettingsAsset = context.GetGameSettingsAsset(); var renderingSettings = gameSettingsAsset.GetOrCreate <RenderingSettings>(context.Platform); result.BuildSteps = new ListBuildStep(); var prereqSteps = new Queue <BuildStep>(); // create the registry containing the sprite assets texture index association var imageToTextureUrl = new Dictionary <SpriteInfo, string>(); var colorSpace = context.GetColorSpace(); // create and add import texture commands if (asset.Sprites != null && !asset.Packing.Enabled) { // sort sprites by referenced texture. var spriteByTextures = asset.Sprites.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 textureUrl = SpriteSheetAsset.BuildTextureUrl(assetItem.Location, i); var spriteAssetArray = spriteByTextures[i].ToArray(); foreach (var spriteAsset in spriteAssetArray) { imageToTextureUrl[spriteAsset] = textureUrl; } // create an texture asset. var textureAsset = new TextureAsset { Id = AssetId.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) IsStreamable = asset.IsStreamable && asset.Type != SpriteSheetType.UI, IsCompressed = asset.IsCompressed, GenerateMipmaps = asset.GenerateMipmaps, Type = new ColorTextureType { Alpha = asset.Alpha, PremultiplyAlpha = asset.PremultiplyAlpha, ColorKeyColor = asset.ColorKeyColor, ColorKeyEnabled = asset.ColorKeyEnabled, UseSRgbSampling = true, } }; // Get absolute path of asset source on disk var assetDirectory = assetItem.FullPath.GetParent(); var assetSource = UPath.Combine(assetDirectory, spriteAssetArray[0].Source); // add the texture build command. var textureConvertParameters = new TextureConvertParameters(assetSource, textureAsset, context.Platform, context.GetGraphicsPlatform(assetItem.Package), renderingSettings.DefaultGraphicsProfile, gameSettingsAsset.GetOrCreate <TextureSettings>().TextureQuality, colorSpace); var textureConvertCommand = new TextureAssetCompiler.TextureConvertCommand(textureUrl, textureConvertParameters, assetItem.Package); var assetBuildStep = new AssetBuildStep(new AssetItem(textureUrl, textureAsset)); assetBuildStep.Add(textureConvertCommand); prereqSteps.Enqueue(assetBuildStep); result.BuildSteps.Add(assetBuildStep); } } if (!result.HasErrors) { var parameters = new SpriteSheetParameters(asset, imageToTextureUrl, context.Platform, context.GetGraphicsPlatform(assetItem.Package), renderingSettings.DefaultGraphicsProfile, gameSettingsAsset.GetOrCreate <TextureSettings>().TextureQuality, colorSpace); var assetBuildStep = new AssetBuildStep(assetItem); assetBuildStep.Add(new SpriteSheetCommand(targetUrlInStorage, parameters, assetItem.Package)); result.BuildSteps.Add(assetBuildStep); while (prereqSteps.Count > 0) { var prereq = prereqSteps.Dequeue(); BuildStep.LinkBuildSteps(prereq, assetBuildStep); } } }
public static ColorSpace GetColorSpace(this AssetCompilerContext context) { var settings = context.GetGameSettingsAsset(); return(settings.ColorSpace); }
protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result) { var asset = (SkyboxAsset)assetItem.Asset; var colorSpace = context.GetColorSpace(); result.BuildSteps = new AssetBuildStep(assetItem); var prereqs = new Queue <BuildStep>(); // build the textures for windows (needed for skybox compilation) foreach (var dependency in asset.GetDependencies()) { var dependencyItem = assetItem.Package.Assets.Find(dependency.Id); if (dependencyItem?.Asset is TextureAsset) { var textureAsset = (TextureAsset)dependencyItem.Asset; // Get absolute path of asset source on disk var assetSource = GetAbsolutePath(dependencyItem, textureAsset.Source); // Create a synthetic url var textureUrl = SkyboxGenerator.BuildTextureForSkyboxGenerationLocation(dependencyItem.Location); var gameSettingsAsset = context.GetGameSettingsAsset(); var renderingSettings = gameSettingsAsset.GetOrCreate <RenderingSettings>(context.Platform); // Select the best graphics profile var graphicsProfile = renderingSettings.DefaultGraphicsProfile >= GraphicsProfile.Level_10_0 ? renderingSettings.DefaultGraphicsProfile : GraphicsProfile.Level_10_0; var textureAssetItem = new AssetItem(textureUrl, textureAsset); // Create and add the texture command. var textureParameters = new TextureConvertParameters(assetSource, textureAsset, PlatformType.Windows, GraphicsPlatform.Direct3D11, graphicsProfile, gameSettingsAsset.GetOrCreate <TextureSettings>().TextureQuality, colorSpace); var prereqStep = new AssetBuildStep(textureAssetItem); prereqStep.Add(new TextureAssetCompiler.TextureConvertCommand(textureUrl, textureParameters, assetItem.Package)); result.BuildSteps.Add(prereqStep); prereqs.Enqueue(prereqStep); } } // add the skybox command itself. IEnumerable <ObjectUrl> InputFilesGetter() { var skyboxAsset = (SkyboxAsset)assetItem.Asset; foreach (var dependency in skyboxAsset.GetDependencies()) { var dependencyItem = assetItem.Package.Assets.Find(dependency.Id); if (dependencyItem?.Asset is TextureAsset) { yield return(new ObjectUrl(UrlType.Content, dependency.Location)); } } } var assetStep = new CommandBuildStep(new SkyboxCompileCommand(targetUrlInStorage, asset, assetItem.Package) { InputFilesGetter = InputFilesGetter }); result.BuildSteps.Add(assetStep); while (prereqs.Count > 0) { var prereq = prereqs.Dequeue(); BuildStep.LinkBuildSteps(prereq, assetStep); } }