Skip to content

Commit

Permalink
[SDK-348] Feature/test updates (#113)
Browse files Browse the repository at this point in the history
- cleanup and updated tests
  • Loading branch information
HarrisonHough authored Sep 5, 2023
1 parent 9468d81 commit 60630df
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 15 deletions.
113 changes: 103 additions & 10 deletions Tests/Editor/AvatarAPITests.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -16,12 +18,12 @@ public class AvatarAPITests
private const int AVATAR_CONFIG_BLEND_SHAPE_COUNT_MED = 15;

private readonly List<GameObject> avatars = new List<GameObject>();

private AvatarConfig avatarConfigHigh;
private AvatarConfig avatarConfigLow;
private AvatarConfig avatarConfigMed;
private AvatarLoaderSettings settings;

[OneTimeSetUp]
public void Init()
{
Expand All @@ -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);
}
Expand Down Expand Up @@ -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>();
avatarConfig.Lod = Lod.Low;
avatarConfig.TextureAtlas = TextureAtlas.Low;
avatarConfig.MorphTargets = new List<string> { "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>();
avatarConfig.Lod = Lod.Low;
avatarConfig.TextureAtlas = TextureAtlas.None;
avatarConfig.MorphTargets = new List<string> { "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>();
avatarConfig.Lod = Lod.Low;
avatarConfig.TextureAtlas = TextureAtlas.Low;
avatarConfig.MorphTargets = new List<string> { "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);
}
}
Expand Down
16 changes: 11 additions & 5 deletions Tests/Editor/AvatarLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
avatarConfig.Lod = Lod.Low;
avatarConfig.TextureAtlas = TextureAtlas.Low;
avatarConfig.TextureChannel = Array.Empty<TextureChannel>();

var loader = new AvatarObjectLoader();
loader.OnCompleted += (sender, args) =>
{
avatar = args.Avatar;
};
loader.AvatarConfig = ScriptableObject.CreateInstance<AvatarConfig>();
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);
Expand All @@ -195,11 +199,13 @@ public IEnumerator AvatarLoader_Low_LOD_Smaller_than_High_LOD()

Object.DestroyImmediate(avatar);
loader = new AvatarObjectLoader();
loader.AvatarConfig = ScriptableObject.CreateInstance<AvatarConfig>();
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);
Expand Down

0 comments on commit 60630df

Please sign in to comment.