mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-01 23:43:20 -05:00
add test
This commit is contained in:
parent
737359b295
commit
1cee06e83e
|
|
@ -1,3 +1,5 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using VRMShaders;
|
||||
|
|
@ -31,5 +33,66 @@ namespace UniGLTF
|
|||
Assert.AreEqual(glFilter.LINEAR_MIPMAP_LINEAR, sampler.minFilter);
|
||||
Assert.AreEqual(glFilter.LINEAR_MIPMAP_LINEAR, sampler.magFilter);
|
||||
}
|
||||
|
||||
static FileInfo Find(DirectoryInfo current, string target)
|
||||
{
|
||||
foreach (var child in current.EnumerateFiles())
|
||||
{
|
||||
if (child.Name == target)
|
||||
{
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var child in current.EnumerateDirectories())
|
||||
{
|
||||
var found = Find(child, target);
|
||||
if (found != null)
|
||||
{
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static FileInfo GetGltfTestModelPath(string name)
|
||||
{
|
||||
var env = System.Environment.GetEnvironmentVariable("GLTF_SAMPLE_MODELS");
|
||||
if (string.IsNullOrEmpty(env))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var root = new DirectoryInfo($"{env}/2.0");
|
||||
if (!root.Exists)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return Find(root, name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TextureExtractTest()
|
||||
{
|
||||
var path = GetGltfTestModelPath("BoomBox.glb");
|
||||
if (path == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// parse
|
||||
var parser = new GltfParser();
|
||||
parser.ParsePath(path.FullName);
|
||||
|
||||
// load
|
||||
var loader = new ImporterContext(parser);
|
||||
loader.Load();
|
||||
|
||||
// extractor
|
||||
var extractor = new TextureExtractor(parser, UnityPath.FromUnityPath(""), loader.TextureFactory.Textures.Select(x => (new SubAssetKey(typeof(Texture2D), x.Texture.name), x.Texture)).ToArray());
|
||||
var m = GltfTextureEnumerator.EnumerateTexturesForMaterial(parser, 0).FirstOrDefault(x => x.Item1.Name == "texture_1.standard");
|
||||
extractor.Extract(m.Item1, m.Item2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user