add VRM_TEST_MODELS

This commit is contained in:
ousttrue 2021-03-17 20:58:46 +09:00
parent 1f9f5e7498
commit 199bc3e170
6 changed files with 120 additions and 1 deletions

View File

@ -6,7 +6,7 @@ using UnityEngine;
namespace UniGLTF
{
public class LoadTests
public class GltfLoadTests
{
static IEnumerable<FileInfo> EnumerateGltfFiles(DirectoryInfo dir)
{

View File

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bd80effebd71ba445976e6285b714f1c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using UniGLTF;
using UnityEngine;
namespace VRM
{
public class VRMLoadTest
{
static IEnumerable<FileInfo> EnumerateGltfFiles(DirectoryInfo dir)
{
if (dir.Name == ".git")
{
yield break;
}
foreach (var child in dir.EnumerateDirectories())
{
foreach (var x in EnumerateGltfFiles(child))
{
yield return x;
}
}
foreach (var child in dir.EnumerateFiles())
{
switch (child.Extension.ToLower())
{
case ".vrm":
yield return child;
break;
}
}
}
static void Message(string path, Exception exception)
{
while (exception.InnerException != null)
{
exception = exception.InnerException;
}
{
Debug.LogError($"LoadError: {path}");
Debug.LogException(exception);
}
}
static void Load(FileInfo gltf, DirectoryInfo root)
{
var parser = new GltfParser();
try
{
parser.ParsePath(gltf.FullName);
}
catch (Exception ex)
{
Debug.LogError($"ParseError: {gltf}");
Debug.LogException(ex);
}
try
{
using (var importer = new VRMImporterContext(parser))
{
importer.Load();
}
}
catch (Exception ex)
{
Message(gltf.FullName.Substring(root.FullName.Length), ex);
}
}
[Test]
public void VrmTestModelsTests()
{
var env = System.Environment.GetEnvironmentVariable("VRM_TEST_MODELS");
if (string.IsNullOrEmpty(env))
{
return;
}
var root = new DirectoryInfo(env);
if (!root.Exists)
{
return;
}
foreach (var gltf in EnumerateGltfFiles(root))
{
Load(gltf, root);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f4a4042cfb50bb84495fd90f548683ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: