diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfTextureEnumerator.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfTextureEnumerator.cs index 074816122..15147905b 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfTextureEnumerator.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfTextureEnumerator.cs @@ -52,11 +52,14 @@ namespace UniGLTF public static IEnumerable Enumerate(glTF gltf) { + var used = new HashSet(); foreach (var material in gltf.materials) { foreach (var textureInfo in EnumerateTextures(gltf, material)) { - yield return textureInfo; + if(used.Add(textureInfo)){ + yield return textureInfo; + } } } } diff --git a/Assets/UniGLTF/Tests/UniGLTF/GltfLoadTests.cs b/Assets/UniGLTF/Tests/UniGLTF/GltfLoadTests.cs index 2f60da547..e27914c53 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/GltfLoadTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/GltfLoadTests.cs @@ -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); } } + /// + /// Extract をテスト + /// + /// + /// + 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); } } }