From 40e5de26c2403e9483503a453d6faa05dd9c0ecf Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Fri, 15 Oct 2021 17:04:57 +0900 Subject: [PATCH] =?UTF-8?q?Editor=20Import=20=E3=81=AB=E3=81=8A=E3=81=84?= =?UTF-8?q?=E3=81=A6=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=B7=E3=82=B9?= =?UTF-8?q?=E3=83=86=E3=83=A0=E3=81=AB=E5=B1=95=E9=96=8B=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=81=86=E3=82=8B=20Asset=20=E3=81=AE=20Name=20=E3=81=AF?= =?UTF-8?q?=E3=80=81=E5=A4=A7=E6=96=87=E5=AD=97=E5=B0=8F=E6=96=87=E5=AD=97?= =?UTF-8?q?=E3=81=AE=E9=81=95=E3=81=84=E3=81=AF=E5=90=8C=E4=B8=80=E3=81=A8?= =?UTF-8?q?=E3=81=97=E3=81=A6=E5=88=A4=E6=96=AD=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UniGLTF/IO/Parser/GlbLowLevelParser.cs | 9 ++-- .../UniGLTF/Tests/UniGLTF/GlbParserTests.cs | 41 +++++++++++++++++++ .../Tests/UniGLTF/GlbParserTests.cs.meta | 3 ++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 Assets/UniGLTF/Tests/UniGLTF/GlbParserTests.cs create mode 100644 Assets/UniGLTF/Tests/UniGLTF/GlbParserTests.cs.meta diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs index b518b9b9a..a0ecdfd51 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs @@ -174,7 +174,8 @@ namespace UniGLTF /// private static void FixTextureNameUnique(glTF GLTF) { - var used = new HashSet(); + // NOTE: Windows FileSystem は大文字小文字の違いは同名ファイルとして扱ってしまうため, IgnoreCase で評価する. + var used = new HashSet(StringComparer.OrdinalIgnoreCase); for (var textureIdx = 0; textureIdx < GLTF.textures.Count; ++textureIdx) { var gltfTexture = GLTF.textures[textureIdx]; @@ -200,7 +201,8 @@ namespace UniGLTF private static void FixMaterialNameUnique(glTF GLTF) { - var used = new HashSet(); + // NOTE: Windows FileSystem は大文字小文字の違いは同名ファイルとして扱ってしまうため, IgnoreCase で評価する. + var used = new HashSet(StringComparer.OrdinalIgnoreCase); for (var materialIdx = 0; materialIdx < GLTF.materials.Count; ++materialIdx) { var material = GLTF.materials[materialIdx]; @@ -231,7 +233,8 @@ namespace UniGLTF private static void FixAnimationNameUnique(glTF GLTF) { - var used = new HashSet(); + // NOTE: Windows FileSystem は大文字小文字の違いは同名ファイルとして扱ってしまうため, IgnoreCase で評価する. + var used = new HashSet(StringComparer.OrdinalIgnoreCase); for (int i = 0; i < GLTF.animations.Count; ++i) { var animation = GLTF.animations[i]; diff --git a/Assets/UniGLTF/Tests/UniGLTF/GlbParserTests.cs b/Assets/UniGLTF/Tests/UniGLTF/GlbParserTests.cs new file mode 100644 index 000000000..4e3b2e505 --- /dev/null +++ b/Assets/UniGLTF/Tests/UniGLTF/GlbParserTests.cs @@ -0,0 +1,41 @@ +using System; +using NUnit.Framework; + +namespace UniGLTF +{ + public sealed class GlbParserTests + { + [Test] + public void TextureNameUniqueness() + { + var gltfData = new glTF(); + gltfData.asset.version = "2.0"; + gltfData.buffers.Add(new glTFBuffer(new ArrayByteBuffer(Array.Empty()))); + gltfData.textures.Add(new glTFTexture + { + name = "FooBar", + source = 0, + }); + gltfData.textures.Add(new glTFTexture + { + name = "foobar", + source = 1, + }); + gltfData.images.Add(new glTFImage + { + name = "HogeFuga", + }); + gltfData.images.Add(new glTFImage + { + name = "hogefuga", + }); + + var parser = new GlbLowLevelParser("Test", gltfData.ToGlbBytes()); + var data = parser.Parse(); + + Assert.AreEqual("FooBar", data.GLTF.textures[0].name); + // NOTE: 大文字小文字が違うだけの名前は、同一としてみなされ、Suffix が付く。 + Assert.AreEqual("foobar__UNIGLTF__DUPLICATED__2", data.GLTF.textures[1].name); + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Tests/UniGLTF/GlbParserTests.cs.meta b/Assets/UniGLTF/Tests/UniGLTF/GlbParserTests.cs.meta new file mode 100644 index 000000000..d50809b18 --- /dev/null +++ b/Assets/UniGLTF/Tests/UniGLTF/GlbParserTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 21904270c266400aa6fe5edf3915a31e +timeCreated: 1634282839 \ No newline at end of file