add LoadTests

https://github.com/KhronosGroup/glTF-Sample-Models
This commit is contained in:
ousttrue
2021-03-17 19:59:45 +09:00
parent bf4fca66c0
commit 67b083b10f
2 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using UnityEngine;
namespace UniGLTF
{
public class LoadTests
{
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 ".gltf":
case ".glb":
yield return child;
break;
}
}
}
static void Load(FileInfo gltf)
{
var parser = new GltfParser();
try
{
parser.ParsePath(gltf.FullName);
}
catch (Exception)
{
Debug.LogError($"ParseError: {gltf}");
throw;
}
try
{
using (var importer = new ImporterContext(parser))
{
importer.Load();
}
}
catch (Exception)
{
Debug.LogError($"LoadError: {gltf}");
throw;
}
}
[Test]
public void GltfSampleModelsTests()
{
var env = System.Environment.GetEnvironmentVariable("GLTF_SAMPLE_MODELS");
if (string.IsNullOrEmpty(env))
{
return;
}
var root = new DirectoryInfo(env);
if (!root.Exists)
{
return;
}
foreach (var gltf in EnumerateGltfFiles(root))
{
Load(gltf);
}
}
}
}

View File

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