From 60630df3556761b1efaed115fcd542db4ba0cd46 Mon Sep 17 00:00:00 2001 From: Harrison Hough Date: Tue, 5 Sep 2023 08:22:02 +0300 Subject: [PATCH] [SDK-348] Feature/test updates (#113) - cleanup and updated tests --- Tests/Editor/AvatarAPITests.cs | 113 +++++++++++++++++++++++++++--- Tests/Editor/AvatarLoaderTests.cs | 16 +++-- 2 files changed, 114 insertions(+), 15 deletions(-) diff --git a/Tests/Editor/AvatarAPITests.cs b/Tests/Editor/AvatarAPITests.cs index c4989fcd..06a3c57b 100644 --- a/Tests/Editor/AvatarAPITests.cs +++ b/Tests/Editor/AvatarAPITests.cs @@ -1,9 +1,11 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using NUnit.Framework; using UnityEngine; using UnityEngine.TestTools; +using Object = UnityEngine.Object; namespace ReadyPlayerMe.Core.Tests { @@ -16,12 +18,12 @@ public class AvatarAPITests private const int AVATAR_CONFIG_BLEND_SHAPE_COUNT_MED = 15; private readonly List avatars = new List(); - + private AvatarConfig avatarConfigHigh; private AvatarConfig avatarConfigLow; private AvatarConfig avatarConfigMed; private AvatarLoaderSettings settings; - + [OneTimeSetUp] public void Init() { @@ -31,13 +33,13 @@ public void Init() settings = AvatarLoaderSettings.LoadSettings(); settings.AvatarCachingEnabled = false; } - + [OneTimeTearDown] public void Cleanup() { AvatarCache.Clear(); - foreach (var avatar in avatars) + foreach (GameObject avatar in avatars) { Object.DestroyImmediate(avatar); } @@ -225,20 +227,111 @@ public IEnumerator AvatarLoader_Avatar_API_MorphTargets_Oculus() } [Test] - public async Task AvatarLoader_Avatar_API_MeshOptCompression() + public async Task AvatarLoader_Avatar_API_MeshOpt_SingleMesh() { var avatarConfig = ScriptableObject.CreateInstance(); avatarConfig.Lod = Lod.Low; avatarConfig.TextureAtlas = TextureAtlas.Low; avatarConfig.MorphTargets = new List { "none" }; avatarConfig.TextureChannel = new[] { TextureChannel.BaseColor }; + byte[] normalBytes = null; + byte[] meshOptBytes = null; var downloader = new AvatarDownloader(); - var normalBytes = await downloader.DownloadIntoMemory(AVATAR_API_AVATAR_URL, avatarConfig); - + try + { + normalBytes = await downloader.DownloadIntoMemory(AVATAR_API_AVATAR_URL, avatarConfig); + } + catch (Exception ex) + { + Assert.Fail($"Downloading normal bytes failed with exception: {ex}"); + return; + } + + avatarConfig.UseMeshOptCompression = true; + try + { + meshOptBytes = await downloader.DownloadIntoMemory(AVATAR_API_AVATAR_URL, avatarConfig); + } + catch (Exception ex) + { + Assert.Fail($"Downloading meshOpt bytes failed with exception: {ex}"); + return; + } + + Assert.Less(meshOptBytes.Length, normalBytes.Length); + } + + [Test] + public async Task AvatarLoader_Avatar_API_MeshOpt_MultiMesh() + { + var avatarConfig = ScriptableObject.CreateInstance(); + avatarConfig.Lod = Lod.Low; + avatarConfig.TextureAtlas = TextureAtlas.None; + avatarConfig.MorphTargets = new List { "none" }; + avatarConfig.TextureChannel = new[] { TextureChannel.BaseColor }; + + byte[] normalBytes; + byte[] meshOptBytes; + + var downloader = new AvatarDownloader(); + try + { + normalBytes = await downloader.DownloadIntoMemory(AVATAR_API_AVATAR_URL, avatarConfig); + } + catch (Exception ex) + { + Assert.Fail($"Downloading normal bytes failed with exception: {ex}"); + return; + } + avatarConfig.UseMeshOptCompression = true; - var meshOptBytes = await downloader.DownloadIntoMemory(AVATAR_API_AVATAR_URL, avatarConfig); - + try + { + meshOptBytes = await downloader.DownloadIntoMemory(AVATAR_API_AVATAR_URL, avatarConfig); + } + catch (Exception ex) + { + Assert.Fail($"Downloading meshOpt bytes failed with exception: {ex}"); + return; + } + + Assert.Less(meshOptBytes.Length, normalBytes.Length); + } + + [Test] + public async Task AvatarLoader_Avatar_API_DracoCompression() + { + var avatarConfig = ScriptableObject.CreateInstance(); + avatarConfig.Lod = Lod.Low; + avatarConfig.TextureAtlas = TextureAtlas.Low; + avatarConfig.MorphTargets = new List { "none" }; + avatarConfig.TextureChannel = new[] { TextureChannel.BaseColor }; + byte[] normalBytes = null; + byte[] meshOptBytes = null; + + var downloader = new AvatarDownloader(); + try + { + normalBytes = await downloader.DownloadIntoMemory(AVATAR_API_AVATAR_URL, avatarConfig); + } + catch (Exception ex) + { + Assert.Fail($"Downloading normal avatar bytes failed with exception: {ex}"); + return; + } + + avatarConfig.UseDracoCompression = true; + try + { + meshOptBytes = await downloader.DownloadIntoMemory(AVATAR_API_AVATAR_URL, avatarConfig); + } + catch (Exception ex) + { + Assert.Fail($"Downloading draco compression avatar bytes failed with exception: {ex}"); + return; + } + Assert.Less(meshOptBytes.Length, normalBytes.Length); } } diff --git a/Tests/Editor/AvatarLoaderTests.cs b/Tests/Editor/AvatarLoaderTests.cs index 23b606fe..99aa99a1 100644 --- a/Tests/Editor/AvatarLoaderTests.cs +++ b/Tests/Editor/AvatarLoaderTests.cs @@ -179,14 +179,18 @@ public IEnumerator AvatarLoader_Cancel_Loading() public IEnumerator AvatarLoader_Low_LOD_Smaller_than_High_LOD() { var failureType = FailureType.None; - + + var avatarConfig = ScriptableObject.CreateInstance(); + avatarConfig.Lod = Lod.Low; + avatarConfig.TextureAtlas = TextureAtlas.Low; + avatarConfig.TextureChannel = Array.Empty(); + var loader = new AvatarObjectLoader(); loader.OnCompleted += (sender, args) => { avatar = args.Avatar; }; - loader.AvatarConfig = ScriptableObject.CreateInstance(); - loader.AvatarConfig.Lod = Lod.Low; + loader.AvatarConfig = avatarConfig; loader.OnFailed += (sender, args) => { failureType = args.Type; }; loader.LoadAvatar(TestAvatarData.DefaultAvatarUri.ModelUrl); yield return new WaitUntil(() => avatar != null || failureType != FailureType.None); @@ -195,11 +199,13 @@ public IEnumerator AvatarLoader_Low_LOD_Smaller_than_High_LOD() Object.DestroyImmediate(avatar); loader = new AvatarObjectLoader(); - loader.AvatarConfig = ScriptableObject.CreateInstance(); - loader.AvatarConfig.Lod = Lod.High; + avatarConfig.Lod = Lod.High; + loader.AvatarConfig = avatarConfig; + loader.OnCompleted += (sender, args) => { avatar = args.Avatar; + Object.DestroyImmediate(avatarConfig); }; loader.OnFailed += (sender, args) => { failureType = args.Type; }; loader.LoadAvatar(TestAvatarData.DefaultAvatarUri.ModelUrl);