From 471daaf5bf1a1220e1902eee96c9f363625fea29 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 24 Feb 2021 22:14:08 +0900 Subject: [PATCH] RenameImageFromTexture --- .../UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs index 840ce980c..020337717 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs @@ -204,12 +204,32 @@ namespace UniGLTF } } + void RenameImageFromTexture(int i) + { + foreach (var texture in GLTF.textures) + { + if (texture.source == i) + { + if (!string.IsNullOrEmpty(texture.name)) + { + GLTF.images[i].name = texture.name; + return; + } + } + } + } + void FixImageNameUnique() { var used = new HashSet(); for (int i = 0; i < GLTF.images.Count; ++i) { var image = GLTF.images[i]; + if (string.IsNullOrEmpty(image.name)) + { + RenameImageFromTexture(i); + } + if (string.IsNullOrEmpty(image.name)) { var newName = $"image_{i}";