protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result) { var asset = (SpriteFontAsset)assetItem.Asset; UFile assetAbsolutePath = assetItem.FullPath; var colorSpace = context.GetColorSpace(); var fontTypeSdf = asset.FontType as SignedDistanceFieldSpriteFontType; if (fontTypeSdf != null) { // copy the asset and transform the source and character set file path to absolute paths var assetClone = AssetCloner.Clone(asset); var assetDirectory = assetAbsolutePath.GetParent(); assetClone.FontSource = asset.FontSource; fontTypeSdf.CharacterSet = !string.IsNullOrEmpty(fontTypeSdf.CharacterSet) ? UPath.Combine(assetDirectory, fontTypeSdf.CharacterSet) : null; result.BuildSteps = new AssetBuildStep(assetItem); result.BuildSteps.Add(new SignedDistanceFieldFontCommand(targetUrlInStorage, assetClone, assetItem.Package)); } else if (asset.FontType is RuntimeRasterizedSpriteFontType) { UFile fontPathOnDisk = asset.FontSource.GetFontPath(result); if (fontPathOnDisk == null) { result.Error($"Runtime rasterized font compilation failed. Font {asset.FontSource.GetFontName()} was not found on this machine."); result.BuildSteps = new AssetBuildStep(assetItem); result.BuildSteps.Add(new FailedFontCommand()); return; } var fontImportLocation = FontHelper.GetFontPath(asset.FontSource.GetFontName(), asset.FontSource.Style); result.BuildSteps = new AssetBuildStep(assetItem); result.BuildSteps.Add(new ImportStreamCommand { SourcePath = fontPathOnDisk, Location = fontImportLocation }); result.BuildSteps.Add(new RuntimeRasterizedFontCommand(targetUrlInStorage, asset, assetItem.Package)); } else { var fontTypeStatic = asset.FontType as OfflineRasterizedSpriteFontType; if (fontTypeStatic == null) { throw new ArgumentException("Tried to compile a non-offline rasterized sprite font with the compiler for offline resterized fonts!"); } // copy the asset and transform the source and character set file path to absolute paths var assetClone = AssetCloner.Clone(asset); var assetDirectory = assetAbsolutePath.GetParent(); assetClone.FontSource = asset.FontSource; fontTypeStatic.CharacterSet = !string.IsNullOrEmpty(fontTypeStatic.CharacterSet) ? UPath.Combine(assetDirectory, fontTypeStatic.CharacterSet): null; result.BuildSteps = new AssetBuildStep(assetItem); result.BuildSteps.Add(new OfflineRasterizedFontCommand(targetUrlInStorage, assetClone, colorSpace, assetItem.Package) { InputFilesGetter = () => GetInputFiles(assetItem) }); } }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, SpriteFontAsset asset, AssetCompilerResult result) { var colorSpace = context.GetColorSpace(); if (asset.FontType is SignedDistanceFieldSpriteFontType) { var fontTypeSDF = asset.FontType as SignedDistanceFieldSpriteFontType; // copy the asset and transform the source and character set file path to absolute paths var assetClone = (SpriteFontAsset)AssetCloner.Clone(asset); var assetDirectory = assetAbsolutePath.GetParent(); assetClone.FontSource = asset.FontSource; fontTypeSDF.CharacterSet = !string.IsNullOrEmpty(fontTypeSDF.CharacterSet) ? UPath.Combine(assetDirectory, fontTypeSDF.CharacterSet) : null; result.BuildSteps = new AssetBuildStep(AssetItem) { new SignedDistanceFieldFontCommand(urlInStorage, assetClone) }; } else if (asset.FontType is RuntimeRasterizedSpriteFontType) { UFile fontPathOnDisk; fontPathOnDisk = asset.FontSource.GetFontPath(); var fontImportLocation = FontHelper.GetFontPath(asset.FontSource.GetFontName(), asset.FontSource.Style); result.BuildSteps = new AssetBuildStep(AssetItem) { new ImportStreamCommand { SourcePath = fontPathOnDisk, Location = fontImportLocation }, new RuntimeRasterizedFontCommand(urlInStorage, asset) }; } else { var fontTypeStatic = asset.FontType as OfflineRasterizedSpriteFontType; if (fontTypeStatic == null) { throw new ArgumentException("Tried to compile a dynamic sprite font with compiler for signed distance field fonts"); } // copy the asset and transform the source and character set file path to absolute paths var assetClone = (SpriteFontAsset)AssetCloner.Clone(asset); var assetDirectory = assetAbsolutePath.GetParent(); assetClone.FontSource = asset.FontSource; fontTypeStatic.CharacterSet = !string.IsNullOrEmpty(fontTypeStatic.CharacterSet) ? UPath.Combine(assetDirectory, fontTypeStatic.CharacterSet): null; result.BuildSteps = new AssetBuildStep(AssetItem) { new OfflineRasterizedFontCommand(urlInStorage, assetClone, colorSpace) }; } }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, SpriteFontAsset asset, AssetCompilerResult result) { var colorSpace = context.GetColorSpace(); if (asset.IsDynamic) { UFile fontPathOnDisk; if (!string.IsNullOrEmpty(asset.Source)) { var assetDirectory = assetAbsolutePath.GetParent(); fontPathOnDisk = UPath.Combine(assetDirectory, asset.Source); if (!File.Exists(fontPathOnDisk)) { result.Error("The font source '{0}' does not exist on the PC.", asset.FontName); return; } // set the source filename as font name instead of the font family. asset.FontName = fontPathOnDisk.GetFileName(); } else { fontPathOnDisk = GetFontPath(asset, result); if (fontPathOnDisk == null) { result.Error("The font named '{0}' could not be located on the PC.", asset.FontName); return; } } var fontImportLocation = FontHelper.GetFontPath(asset.FontName, asset.Style); result.BuildSteps = new AssetBuildStep(AssetItem) { new ImportStreamCommand { SourcePath = fontPathOnDisk, Location = fontImportLocation }, new DynamicFontCommand(urlInStorage, asset) }; } else { // copy the asset and transform the source and character set file path to absolute paths var assetClone = (SpriteFontAsset)AssetCloner.Clone(asset); var assetDirectory = assetAbsolutePath.GetParent(); assetClone.Source = !string.IsNullOrEmpty(asset.Source) ? UPath.Combine(assetDirectory, asset.Source): null; assetClone.CharacterSet = !string.IsNullOrEmpty(asset.CharacterSet) ? UPath.Combine(assetDirectory, asset.CharacterSet): null; result.BuildSteps = new AssetBuildStep(AssetItem) { new StaticFontCommand(urlInStorage, assetClone, colorSpace) }; } }
/// <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)); } }
public void TestGetParent() { var dirPath1 = new UDirectory(@"E:\a\b"); var dirPathParent1 = dirPath1.GetParent(); Assert.AreEqual(@"E:/a", dirPathParent1.FullPath); dirPathParent1 = dirPathParent1.GetParent(); Assert.AreEqual(@"E:", dirPathParent1.FullPath); dirPathParent1 = dirPathParent1.GetParent(); Assert.AreEqual(UDirectory.Empty, dirPathParent1); dirPath1 = new UDirectory(@"/a/b"); dirPathParent1 = dirPath1.GetParent(); Assert.AreEqual(@"/a", dirPathParent1.FullPath); dirPathParent1 = dirPathParent1.GetParent(); Assert.AreEqual(@"/", dirPathParent1.FullPath); dirPathParent1 = dirPathParent1.GetParent(); Assert.AreEqual(UDirectory.Empty, dirPathParent1); // Test on file var filePath1 = new UFile(@"/a/b.txt"); dirPathParent1 = filePath1.GetParent(); Assert.AreEqual(@"/a", dirPathParent1.FullPath); }
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 = TextureCommandHelper.ShouldSeparateAlpha(asset.Alpha, asset.Format, context.Platform, context.GetGraphicsProfile()); // 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 } }
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); } }
/// <summary> /// Returns the absolute path on the disk of an <see cref="UFile"/> that is relative to the asset location. /// </summary> /// <param name="assetAbsolutePath">The absolute path of the asset on the disk.</param> /// <param name="relativePath">The path relative to the asset path that must be converted to an absolute path.</param> /// <returns>The absolute path on the disk of the <see cref="relativePath"/> argument.</returns> /// <exception cref="ArgumentException">The <see cref="relativePath"/> argument is a null or empty <see cref="UFile"/>.</exception> protected static UFile GetAbsolutePath(UFile assetAbsolutePath, UFile relativePath) { if (string.IsNullOrEmpty(relativePath)) { throw new ArgumentException("The relativePath argument is null or empty"); } var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, relativePath); return(assetSource); }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, SoundAsset asset, AssetCompilerResult result) { // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, asset.Source); result.BuildSteps = new ListBuildStep { new ImportStreamCommand { DisableCompression = asset is SoundMusicAsset, // Media player need a not compressed file on Android and iOS SourcePath = assetSource, Location = urlInStorage, } }; }
public void TestUPathGetParent() { // First directories var dir = new UDirectory("c:/"); Assert.Equal("c:/", dir.GetParent().FullPath); dir = new UDirectory("c:/a"); Assert.Equal("c:/", dir.GetParent().FullPath); dir = new UDirectory("c:/a/b"); Assert.Equal("c:/a", dir.GetParent().FullPath); dir = new UDirectory("/"); Assert.Equal("/", dir.GetParent().FullPath); dir = new UDirectory("/a"); Assert.Equal("/", dir.GetParent().FullPath); dir = new UDirectory("/a/b"); Assert.Equal("/a", dir.GetParent().FullPath); dir = new UDirectory("a"); Assert.Equal("", dir.GetParent().FullPath); dir = new UDirectory("a/b"); Assert.Equal("a", dir.GetParent().FullPath); // Now with files. var file = new UFile("c:/a.txt"); Assert.Equal("c:/", file.GetParent().FullPath); file = new UFile("c:/a/b.txt"); Assert.Equal("c:/a", file.GetParent().FullPath); file = new UFile("/a.txt"); Assert.Equal("/", file.GetParent().FullPath); file = new UFile("/a/b.txt"); Assert.Equal("/a", file.GetParent().FullPath); file = new UFile("a.txt"); Assert.Equal("", file.GetParent().FullPath); file = new UFile("a/b.txt"); Assert.Equal("a", file.GetParent().FullPath); }
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, string urlInStorage, UFile assetAbsolutePath, TextureAsset asset, AssetCompilerResult result) { if (asset.Source == null) { result.Error("Source cannot be null for Texture Asset [{0}]", asset); return; } // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, asset.Source); result.BuildSteps = new ListBuildStep { new TextureConvertCommand(urlInStorage, new TextureConvertParameters(assetSource, asset, context.Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality(), false)) }; }
/// <summary> /// Ensures that the source of an <see cref="AssetImport"/> exists. If the given asset is not an <see cref="AssetImport"/>, this method simply returns <c>true</c>. /// </summary> /// <param name="result">The <see cref="AssetCompilerResult"/> in which to output log of potential errors.</param> /// <param name="assetImport">The asset to check.</param> /// <param name="assetAbsolutePath">The absolute path of the asset on the disk</param> /// <returns><c>true</c> if the source file exists, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Any of the argument is <c>null</c>.</exception> protected static bool EnsureSourceExists(AssetCompilerResult result, T assetImport, UFile assetAbsolutePath) { if (result == null) { throw new ArgumentNullException("result"); } if (assetImport == null) { throw new ArgumentNullException("assetImport"); } if (assetAbsolutePath == null) { throw new ArgumentNullException("assetAbsolutePath"); } var asset = assetImport as AssetImport; // The asset has no source, so there is no failure if (asset == null) { return(true); } if (string.IsNullOrEmpty(asset.Source)) { result.Error("Source is null for Asset [{0}]", asset); return(false); } // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, asset.Source); // Ensure the file exists if (!File.Exists(assetSource)) { result.Error("Unable to find the source file '{1}' for Asset [{0}]", asset, assetSource); return(false); } return(true); }
/// <summary> /// Ensures that the sources of an <see cref="Asset"/> exist. /// </summary> /// <param name="result">The <see cref="AssetCompilerResult"/> in which to output log of potential errors.</param> /// <param name="asset">The asset to check.</param> /// <param name="assetAbsolutePath">The absolute path of the asset on the disk</param> /// <returns><c>true</c> if the source file exists, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Any of the argument is <c>null</c>.</exception> protected static bool EnsureSourcesExist(AssetCompilerResult result, T asset, UFile assetAbsolutePath) { if (result == null) { throw new ArgumentNullException(nameof(result)); } if (asset == null) { throw new ArgumentNullException(nameof(asset)); } if (assetAbsolutePath == null) { throw new ArgumentNullException(nameof(assetAbsolutePath)); } var collector = new SourceFilesCollector(); var sourceMembers = collector.GetSourceMembers(asset); foreach (var member in sourceMembers) { if (string.IsNullOrEmpty(member.Value)) { result.Error($"Source is null for Asset [{asset}] in property [{member.Key}]"); return(false); } // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, member.Value); // Ensure the file exists if (!File.Exists(assetSource)) { result.Error($"Unable to find the source file '{assetSource}' for Asset [{asset}]"); return(false); } } return(true); }
/// <inheritdoc/> public override Task <ResultStatus> Execute(IExecuteContext executeContext, BuilderContext builderContext) { var steps = new List <BuildStep>(); var urlRoot = originalSourcePath.GetParent(); var stream = new MemoryStream(Encoding.UTF8.GetBytes(((EffectLogAsset)assetItem.Asset).Text)); using (var recordedEffectCompile = new EffectLogStore(stream)) { recordedEffectCompile.LoadNewValues(); foreach (var entry in recordedEffectCompile.GetValues()) { steps.Add(EffectCompileCommand.FromRequest(context, assetItem.Package, urlRoot, entry.Key)); } } Steps = steps; return(base.Execute(executeContext, builderContext)); }
/// <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()) { steps.Add(EffectCompileCommand.FromRequest(context, package, urlRoot, entry.Key)); } } Steps = steps; return(base.Execute(executeContext, builderContext)); }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, ModelAsset asset, AssetCompilerResult result) { if (asset.Source == null) { result.Error("Source cannot be null for Texture Asset [{0}]", asset); return; } // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, asset.Source); var allow32BitIndex = context.GetGraphicsProfile() >= GraphicsProfile.Level_9_2; var allowUnsignedBlendIndices = context.GetGraphicsPlatform() != GraphicsPlatform.OpenGLES; var extension = asset.Source.GetFileExtension(); // compute material and lighting configuration dictionaries here because some null reference can occur var materials = new Dictionary <string, Tuple <Guid, string> >(); var lightings = new Dictionary <string, Tuple <Guid, string> >(); foreach (var meshParam in asset.MeshParameters) { if (meshParam.Value.Material != null) { materials.Add(meshParam.Key, new Tuple <Guid, string>(meshParam.Value.Material.Id, meshParam.Value.Material.Location)); } // Transform AssetReference to Tuple<Guid,UFile> as AssetReference or ContentReference is not serializable (to generate the command hash) // TODO: temporary while the LightingParameters is a Member of MeshMaterialParameter class // TODO: should be passed directly in the Parameters of the mesh - no extra case is required if (meshParam.Value.LightingParameters != null) { lightings.Add(meshParam.Key, new Tuple <Guid, string>(meshParam.Value.LightingParameters.Id, meshParam.Value.LightingParameters.Location)); } } if (ImportFbxCommand.IsSupportingExtensions(extension)) { result.BuildSteps = new ListBuildStep { new ImportFbxCommand { SourcePath = assetSource, Location = urlInStorage, Allow32BitIndex = allow32BitIndex, AllowUnsignedBlendIndices = allowUnsignedBlendIndices, Compact = asset.Compact, PreservedNodes = asset.PreservedNodes, Materials = materials, Lightings = lightings, // TODO: remove when lighting parameters will be behind a key Parameters = asset.MeshParameters.ToDictionary(pair => pair.Key, pair => pair.Value.Parameters), ViewDirectionForTransparentZSort = asset.ViewDirectionForTransparentZSort.HasValue ? asset.ViewDirectionForTransparentZSort.Value : -Vector3.UnitZ, }, new WaitBuildStep(), }; } else if (ImportAssimpCommand.IsSupportingExtensions(extension)) { result.BuildSteps = new ListBuildStep { new ImportAssimpCommand { SourcePath = assetSource, Location = urlInStorage, Allow32BitIndex = allow32BitIndex, AllowUnsignedBlendIndices = allowUnsignedBlendIndices, Compact = asset.Compact, PreservedNodes = asset.PreservedNodes, Materials = materials, Lightings = lightings, // TODO: remove when lighting parameters will be behind a key Parameters = asset.MeshParameters.ToDictionary(pair => pair.Key, pair => pair.Value.Parameters), }, new WaitBuildStep(), }; } else { result.Error("No importer found for model extension '{0}. The model '{1}' can't be imported.", extension, assetSource); } }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, AnimationAsset asset, AssetCompilerResult result) { if (!EnsureSourceExists(result, asset, assetAbsolutePath)) { return; } // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = GetAbsolutePath(assetAbsolutePath, asset.Source); var extension = assetSource.GetFileExtension(); var buildStep = new AssetBuildStep(AssetItem); // Find skeleton asset, if any AssetItem skeleton = null; if (asset.Skeleton != null) { skeleton = AssetItem.Package.FindAssetFromAttachedReference(asset.Skeleton); } var sourceBuildStep = ImportModelCommand.Create(extension); if (sourceBuildStep == null) { result.Error("No importer found for model extension '{0}. The model '{1}' can't be imported.", extension, assetSource); return; } sourceBuildStep.Mode = ImportModelCommand.ExportMode.Animation; sourceBuildStep.SourcePath = assetSource; sourceBuildStep.Location = urlInStorage; sourceBuildStep.AnimationRepeatMode = asset.RepeatMode; sourceBuildStep.AnimationRootMotion = asset.RootMotion; sourceBuildStep.ScaleImport = asset.ScaleImport; sourceBuildStep.SkeletonUrl = skeleton?.Location; var additiveAnimationAsset = asset as AdditiveAnimationAsset; if (additiveAnimationAsset != null) { var baseUrlInStorage = urlInStorage + "_animation_base"; var sourceUrlInStorage = urlInStorage + "_animation_source"; var baseAssetSource = UPath.Combine(assetDirectory, additiveAnimationAsset.BaseSource); var baseExtension = baseAssetSource.GetFileExtension(); sourceBuildStep.Location = sourceUrlInStorage; var baseBuildStep = ImportModelCommand.Create(extension); if (baseBuildStep == null) { result.Error("No importer found for model extension '{0}. The model '{1}' can't be imported.", baseExtension, baseAssetSource); return; } baseBuildStep.Mode = ImportModelCommand.ExportMode.Animation; baseBuildStep.SourcePath = baseAssetSource; baseBuildStep.Location = baseUrlInStorage; baseBuildStep.AnimationRepeatMode = asset.RepeatMode; baseBuildStep.AnimationRootMotion = asset.RootMotion; baseBuildStep.ScaleImport = asset.ScaleImport; baseBuildStep.SkeletonUrl = skeleton?.Location; // Import base and main animation buildStep.Add(sourceBuildStep); buildStep.Add(baseBuildStep); // Wait for both import fbx commands to be completed buildStep.Add(new WaitBuildStep()); // Generate the diff of those two animations buildStep.Add(new AdditiveAnimationCommand(urlInStorage, new AdditiveAnimationParameters(baseUrlInStorage, sourceUrlInStorage, additiveAnimationAsset.Mode))); } else { // Import the main animation buildStep.Add(sourceBuildStep); } result.BuildSteps = buildStep; }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, AnimationAsset asset, AssetCompilerResult result) { // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, asset.Source); var extension = assetSource.GetFileExtension(); var buildStep = new ListBuildStep(); var additiveAnimationAsset = asset as AdditiveAnimationAsset; if (additiveAnimationAsset != null) { var baseUrlInStorage = urlInStorage + "_animation_base"; var sourceUrlInStorage = urlInStorage + "_animation_source"; var baseAssetSource = UPath.Combine(assetDirectory, additiveAnimationAsset.BaseSource); // Import base and main animation if (ImportFbxCommand.IsSupportingExtensions(extension)) { buildStep.Add(new ImportFbxCommand { SourcePath = assetSource, Location = sourceUrlInStorage, ExportType = "animation", AnimationRepeatMode = asset.RepeatMode }); buildStep.Add(new ImportFbxCommand { SourcePath = baseAssetSource, Location = baseUrlInStorage, ExportType = "animation", AnimationRepeatMode = asset.RepeatMode }); } else if (ImportAssimpCommand.IsSupportingExtensions(extension)) { buildStep.Add(new ImportAssimpCommand { SourcePath = assetSource, Location = sourceUrlInStorage, ExportType = "animation", AnimationRepeatMode = asset.RepeatMode }); buildStep.Add(new ImportAssimpCommand { SourcePath = baseAssetSource, Location = baseUrlInStorage, ExportType = "animation", AnimationRepeatMode = asset.RepeatMode }); } // Wait for both import fbx commands to be completed buildStep.Add(new WaitBuildStep()); // Generate the diff of those two animations buildStep.Add(new AdditiveAnimationCommand(urlInStorage, new AdditiveAnimationParameters(baseUrlInStorage, sourceUrlInStorage, additiveAnimationAsset.Mode))); } else { // Import the main animation if (ImportFbxCommand.IsSupportingExtensions(extension)) { buildStep.Add(new ImportFbxCommand { SourcePath = assetSource, Location = urlInStorage, ExportType = "animation", AnimationRepeatMode = asset.RepeatMode }); } else if (ImportAssimpCommand.IsSupportingExtensions(extension)) { buildStep.Add(new ImportAssimpCommand { SourcePath = assetSource, Location = urlInStorage, ExportType = "animation", AnimationRepeatMode = asset.RepeatMode }); } } result.BuildSteps = buildStep; }