Merge pull request #812 from ousttrue/fix/enum_texture_unique

Fix/enum texture unique
This commit is contained in:
ousttrue
2021-03-23 14:21:47 +09:00
committed by GitHub
2 changed files with 34 additions and 4 deletions

View File

@@ -52,11 +52,14 @@ namespace UniGLTF
public static IEnumerable<GetTextureParam> Enumerate(glTF gltf)
{
var used = new HashSet<GetTextureParam>();
foreach (var material in gltf.materials)
{
foreach (var textureInfo in EnumerateTextures(gltf, material))
{
yield return textureInfo;
if(used.Add(textureInfo)){
yield return textureInfo;
}
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
@@ -53,7 +54,7 @@ namespace UniGLTF
}
}
static void Load(FileInfo gltf, DirectoryInfo root)
static void RuntimeLoad(FileInfo gltf, int subStrStart)
{
var parser = new GltfParser();
try
@@ -75,10 +76,34 @@ namespace UniGLTF
}
catch (Exception ex)
{
Message(gltf.FullName.Substring(root.FullName.Length), ex);
Message(gltf.FullName.Substring(subStrStart), ex);
}
}
/// <summary>
/// Extract をテスト
/// </summary>
/// <param name="gltf"></param>
/// <param name="root"></param>
static void EditorLoad(FileInfo gltf, int subStrStart)
{
var parser = new GltfParser();
try
{
parser.ParsePath(gltf.FullName);
}
catch (Exception ex)
{
Debug.LogError($"ParseError: {gltf}");
Debug.LogException(ex);
}
// should unique
var gltfTextures = GltfTextureEnumerator.Enumerate(parser.GLTF);
var distinct = gltfTextures.Distinct().ToArray();
Assert.True(gltfTextures.SequenceEqual(distinct));
}
[Test]
public void GltfSampleModelsTests()
{
@@ -95,7 +120,9 @@ namespace UniGLTF
foreach (var gltf in EnumerateGltfFiles(root))
{
Load(gltf, root);
RuntimeLoad(gltf, root.FullName.Length);
EditorLoad(gltf, root.FullName.Length);
}
}
}