mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-11 21:38:56 -05:00
85
Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs
Normal file
85
Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs.meta
Normal file
11
Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0454ecef7a44cf4280a6f0fcacf3666
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user