diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterImpl.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterImpl.cs index f354671d0..6857afb98 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterImpl.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterImpl.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using UnityEditor; using UnityEditor.Experimental.AssetImporters; using UnityEngine; @@ -27,6 +28,33 @@ namespace UniGLTF AddSubAssets(context, loaded); } + static IEnumerable<(string, UnityEngine.Object)> EnumerateExists(GltfParser parser, UnityPath dir) + { + foreach (var texParam in parser.EnumerateTextures()) + { + switch (texParam.TextureType) + { + case GetTextureParam.METALLIC_GLOSS_PROP: + case GetTextureParam.OCCLUSION_PROP: + break; + + default: + { + var gltfTexture = parser.GLTF.textures.First(y => y.name == texParam.Name); + var gltfImage = parser.GLTF.images[gltfTexture.source]; + if (!string.IsNullOrEmpty(gltfImage.uri)) + { + var child = dir.Child(gltfImage.uri); + var asset = AssetDatabase.LoadAssetAtPath(child.Value); + // Debug.Log($"exists: {child}: {asset}"); + yield return (asset.name, asset); + } + } + break; + } + } + } + /// /// Parse して、UnityObject 化する。 /// @@ -47,7 +75,8 @@ namespace UniGLTF // // Import(create unity objects) // - var context = new ImporterContext(parser, null, externalObjectMap); + var context = new ImporterContext(parser, null, externalObjectMap.Concat( + EnumerateExists(parser, UnityPath.FromUnityPath(assetPath).Parent))); context.InvertAxis = reverseAxis; context.Load(); context.ShowMeshes(); diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs index 63d352b11..b5db58357 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs @@ -229,10 +229,16 @@ namespace UniGLTF for (int i = 0; i < GLTF.textures.Count; ++i) { var gltfTexture = GLTF.textures[i]; + var gltfImage = GLTF.images[gltfTexture.source]; + if (!string.IsNullOrEmpty(gltfImage.uri)) + { + gltfTexture.name = Path.GetFileNameWithoutExtension(gltfImage.uri); + } + if (string.IsNullOrEmpty(gltfTexture.name)) { // use image name - gltfTexture.name = GLTF.images[gltfTexture.source].name; + gltfTexture.name = gltfImage.name; } if (string.IsNullOrEmpty(gltfTexture.name)) {