/// <summary> /// Initializes a new instance of the <see cref="TextureImportEntry"/> class. /// </summary> /// <param name="url">The source file url.</param> /// <param name="resultUrl">The result file url.</param> public TextureImportEntry(string url, string resultUrl) : base(url, resultUrl) { // Try to restore target asset texture import options (usefull for fast reimport) TextureImportSettings.TryRestore(ref _settings, resultUrl); // Try to guess format type based on file name var shortName = System.IO.Path.GetFileNameWithoutExtension(url); string snl = shortName.ToLower(); if (_settings.Type != TextureImportSettings.CustomTextureFormatType.ColorRGB) { // Skip checking } else if (snl.EndsWith("_n") || snl.EndsWith("nrm") || snl.EndsWith("nm") || snl.EndsWith("norm") || snl.Contains("normal") || snl.EndsWith("normals")) { // Normal map _settings.Type = TextureImportSettings.CustomTextureFormatType.NormalMap; } else if (snl.EndsWith("_d") || snl.Contains("diffuse") || snl.Contains("diff") || snl.Contains("color") || snl.Contains("_col") || snl.Contains("basecolor") || snl.Contains("albedo")) { // Albedo or diffuse map _settings.Type = TextureImportSettings.CustomTextureFormatType.ColorRGB; } else if (snl.EndsWith("ao") || snl.EndsWith("ambientocclusion") || snl.EndsWith("gloss") || snl.EndsWith("_r") || snl.EndsWith("_displ") || snl.EndsWith("_disp") || snl.EndsWith("roughness") || snl.EndsWith("_rgh") || snl.EndsWith("_met") || snl.EndsWith("metalness") || snl.EndsWith("displacement") || snl.EndsWith("spec") || snl.EndsWith("specular") || snl.EndsWith("occlusion") || snl.EndsWith("height") || snl.EndsWith("heights") || snl.EndsWith("cavity") || snl.EndsWith("metalic") || snl.EndsWith("metallic")) { // Glossiness, metalness, ambient occlusion, displacement, height, cavity or specular _settings.Type = TextureImportSettings.CustomTextureFormatType.GrayScale; } }
/// <inheritdoc /> public override bool TryOverrideSettings(object settings) { if (settings is TextureImportSettings o) { _settings = o; return(true); } return(false); }
/// <summary> /// Tries the restore the asset import options from the target resource file. /// </summary> /// <param name="options">The options.</param> /// <param name="assetPath">The asset path.</param> /// <returns>True settings has been restored, otherwise false.</returns> public static bool TryRestore(ref TextureImportSettings options, string assetPath) { if (TextureImportEntry.Internal_GetTextureImportOptions(assetPath, out var internalOptions)) { // Restore settings options.FromInternal(ref internalOptions); return(true); } return(false); }
/// <inheritdoc /> public override bool TryOverrideSettings(object settings) { if (settings is TextureImportSettings o) { var sprites = o.Sprites ?? _settings.Sprites; // Preserve sprites if not specified to override _settings = o; _settings.Sprites = sprites; return(true); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="TextureImportEntry"/> class. /// </summary> /// <param name="request">The import request.</param> public TextureImportEntry(ref Request request) : base(ref request) { // Try to guess format type based on file name var snl = System.IO.Path.GetFileNameWithoutExtension(SourceUrl).ToLower(); var extension = System.IO.Path.GetExtension(SourceUrl).ToLower(); if (extension == ".raw") { // Raw image data in 16bit gray-scale, preserve the quality _settings.Type = TextureImportSettings.CustomTextureFormatType.HdrRGBA; _settings.Compress = false; } else if (extension == ".hdr") { // HDR sky texture _settings.Type = TextureImportSettings.CustomTextureFormatType.HdrRGB; } else if (_settings.Type != TextureImportSettings.CustomTextureFormatType.ColorRGB) { // Skip checking } else if (snl.EndsWith("_n") || snl.EndsWith("nrm") || snl.EndsWith("nm") || snl.EndsWith("norm") || snl.Contains("normal") || snl.EndsWith("normals")) { // Normal map _settings.Type = TextureImportSettings.CustomTextureFormatType.NormalMap; } else if (snl.EndsWith("_d") || snl.Contains("diffuse") || snl.Contains("diff") || snl.Contains("color") || snl.Contains("_col") || snl.Contains("basecolor") || snl.Contains("albedo")) { // Albedo or diffuse map _settings.Type = TextureImportSettings.CustomTextureFormatType.ColorRGB; _settings.sRGB = true; } else if (snl.EndsWith("ao") || snl.EndsWith("ambientocclusion") || snl.EndsWith("gloss") || snl.EndsWith("_r") || snl.EndsWith("_displ") || snl.EndsWith("_disp") || snl.EndsWith("roughness") || snl.EndsWith("_rgh") || snl.EndsWith("_met") || snl.EndsWith("metalness") || snl.EndsWith("displacement") || snl.EndsWith("spec") || snl.EndsWith("specular") || snl.EndsWith("occlusion") || snl.EndsWith("height") || snl.EndsWith("heights") || snl.EndsWith("cavity") || snl.EndsWith("metalic") || snl.EndsWith("metallic")) { // Glossiness, metalness, ambient occlusion, displacement, height, cavity or specular _settings.Type = TextureImportSettings.CustomTextureFormatType.GrayScale; } // Try to restore target asset texture import options (useful for fast reimport) TextureImportSettings.TryRestore(ref _settings, ResultUrl); }