diff --git a/Basis/Packages/com.basis.sdk/Scripts/Editor/BasisAvatarValidator.cs b/Basis/Packages/com.basis.sdk/Scripts/Editor/BasisAvatarValidator.cs index c335b7265..a25473173 100644 --- a/Basis/Packages/com.basis.sdk/Scripts/Editor/BasisAvatarValidator.cs +++ b/Basis/Packages/com.basis.sdk/Scripts/Editor/BasisAvatarValidator.cs @@ -17,6 +17,8 @@ public class BasisAvatarValidator private Label passedMessageLabel; public const int MaxTrianglesBeforeWarning = 150000; public const int MeshVertices = 65535; + public const int MaxTextureSizeBeforeWarning = 4096; + public const int MaxTextureSizeWithoutMipMaps = 256; public VisualElement Root; public BasisAvatarValidator(BasisAvatar avatar, VisualElement root) { @@ -152,11 +154,13 @@ public void CreatePassedPanel(VisualElement rootElement) public class BasisValidationIssue { public string Message { get; } + public string FixLabel { get; } public Action Fix { get; } - public BasisValidationIssue(string message, Action fix = null) + public BasisValidationIssue(string message, Action fix = null, string fixLabel = "") { Message = message; Fix = fix; + FixLabel = fixLabel; } } private static void RemoveMissingScripts(GameObject MissingScriptParent) @@ -423,20 +427,46 @@ public void CheckTextures(Renderer Renderer,ref List warni foreach (Texture tex in texturesToCheck) { string texPath = AssetDatabase.GetAssetPath(tex); - if (!string.IsNullOrEmpty(texPath)) + if (string.IsNullOrEmpty(texPath)) { - TextureImporter texImporter = AssetImporter.GetAtPath(texPath) as TextureImporter; - if (texImporter != null) + continue; + } + + TextureImporter texImporter = AssetImporter.GetAtPath(texPath) as TextureImporter; + if (texImporter == null) + { + continue; + } + + // Prompt to enable mip maps on sufficiently large textures + if (texImporter.maxTextureSize > MaxTextureSizeWithoutMipMaps && !texImporter.mipmapEnabled) + { + warnings.Add(new BasisValidationIssue($"Texture \"{tex.name}\" does not have Mip Maps enabled. This will negatively affect its performance ranking.",() => { - if (!texImporter.streamingMipmaps) - { - warnings.Add(new BasisValidationIssue($"Texture \"{tex.name}\" does not have Streaming Mip Maps enabled. this will effect negatively its performance ranking",null)); - } - if(texImporter.maxTextureSize > 4096) - { - warnings.Add(new BasisValidationIssue($"Texture \"{tex.name}\" is {texImporter.maxTextureSize} this will impact performance negatively", null)); - } - } + texImporter.mipmapEnabled = true; + texImporter.streamingMipmaps = true; // all mip maps should be streamed + texImporter.SaveAndReimport(); + }, $"Enable Mip Maps on \"{tex.name}\"")); + } + + // Enforce streaming mip maps where mip maps are enabled + if (texImporter.mipmapEnabled && !texImporter.streamingMipmaps) + { + warnings.Add(new BasisValidationIssue($"Texture \"{tex.name}\" does not have Streaming Mip Maps enabled. This will negatively affect its performance ranking.", () => + { + texImporter.streamingMipmaps = true; + texImporter.SaveAndReimport(); + }, $"Enable Streaming Mip Maps on \"{tex.name}\"")); + } + + // Warn on very large textures + if(texImporter.maxTextureSize > MaxTextureSizeBeforeWarning) + { + warnings.Add(new BasisValidationIssue($"Texture \"{tex.name}\" is {texImporter.maxTextureSize} (should be <= {MaxTextureSizeBeforeWarning}). This will negatively affect its performance ranking.", (() => + { + texImporter.maxTextureSize = MaxTextureSizeBeforeWarning; + texImporter.SaveAndReimport(); + }), $"Resize \"{tex.name}\" to {MaxTextureSizeBeforeWarning}")); } } } @@ -497,7 +527,7 @@ private void ShowErrorPanel(VisualElement Root, List error Action ActFix = issue.Fix; if (ActFix != null) { - AutoFixButton(Root, ActFix, issue.Message); + AutoFixButton(Root, ActFix, issue.Message, true); } if (!IssueList.Exists(i => i == issue.Message)) { @@ -520,7 +550,8 @@ private void ShowWarningPanel(VisualElement Root,List warn Action ActFix = issue.Fix; if (ActFix != null) { - AutoFixButton(Root, ActFix, issue.Message); + string actionTitle = string.IsNullOrWhiteSpace(issue.FixLabel) ? issue.Message : issue.FixLabel; + AutoFixButton(Root, ActFix, actionTitle, false); } if (!warningsList.Exists(i => i==issue.Message)) { @@ -540,7 +571,7 @@ public void ClearFixButtons(VisualElement rootElement) FixMeButtons.Clear(); } public List