diff --git a/Scripts/Format/VRMImporter.cs b/Scripts/Format/VRMImporter.cs index f31d68784..5618a16d2 100644 --- a/Scripts/Format/VRMImporter.cs +++ b/Scripts/Format/VRMImporter.cs @@ -290,31 +290,22 @@ namespace VRM { var x = new TextureItem(context.GLTF, i); x.Process(context.GLTF, storage); - context.Textures.Add(x); + context.AddTexture(x); yield return null; } } static IEnumerator LoadMaterials(VRMImporterContext context) { - Func getTexture = x => - { - if (x < 0 || x >= context.Textures.Count) - { - return null; - } - return context.Textures[x]; - }; - if (context.GLTF.materials == null || !context.GLTF.materials.Any()) { - context.AddMaterial(context.MaterialImporter.CreateMaterial(0, null, getTexture)); + context.AddMaterial(context.MaterialImporter.CreateMaterial(0, null)); } else { for (int i = 0; i < context.GLTF.materials.Count; ++i) { - context.AddMaterial(context.MaterialImporter.CreateMaterial(i, context.GLTF.materials[i], getTexture)); + context.AddMaterial(context.MaterialImporter.CreateMaterial(i, context.GLTF.materials[i])); yield return null; } } @@ -448,7 +439,7 @@ namespace VRM texture.Process(ctx.GLTF, ctx.Storage); return texture; }) - .ContinueWith(Scheduler.ThreadPool, x => ctx.Textures.Add(x)); + .ContinueWith(Scheduler.ThreadPool, x => ctx.AddTexture(x)); } }) .ContinueWithCoroutine(Scheduler.MainThread, () => LoadMaterials(ctx)) diff --git a/Scripts/Format/VRMImporterContext.cs b/Scripts/Format/VRMImporterContext.cs index a1c5a3506..d1800518e 100644 --- a/Scripts/Format/VRMImporterContext.cs +++ b/Scripts/Format/VRMImporterContext.cs @@ -29,10 +29,11 @@ namespace VRM meta.Reference = gltfMeta.reference; meta.Title = gltfMeta.title; - if (gltfMeta.texture >= 0 && gltfMeta.texture < Textures.Count) + var thumbnail = GetTexture(gltfMeta.texture); + if (thumbnail!=null) { // ロード済み - meta.Thumbnail = Textures[gltfMeta.texture].Texture; + meta.Thumbnail = thumbnail.Texture; } else if (createThumbnail) { diff --git a/Scripts/Format/VRMMaterialImporter.cs b/Scripts/Format/VRMMaterialImporter.cs index 03aada0a6..aecc57bfd 100644 --- a/Scripts/Format/VRMMaterialImporter.cs +++ b/Scripts/Format/VRMMaterialImporter.cs @@ -9,7 +9,7 @@ namespace VRM public class VRMMaterialImporter : MaterialImporter { List m_materials; - public VRMMaterialImporter(ImporterContext context, List materials) : base(new ShaderStore(context, "VRM/UnlitTexture")) + public VRMMaterialImporter(ImporterContext context, List materials) : base(new ShaderStore(context, "VRM/UnlitTexture"), context) { m_materials = materials; /* @@ -47,7 +47,7 @@ namespace VRM "VRM/MToon", }; - public override Material CreateMaterial(int i, glTFMaterial src, Func getTexture) + public override Material CreateMaterial(int i, glTFMaterial src) { var item = m_materials[i]; var shaderName = item.shader; @@ -60,12 +60,12 @@ namespace VRM if (VRM_SHADER_NAMES.Contains(shaderName)) { Debug.LogErrorFormat("shader {0} not found. set Assets/VRM/Shaders/VRMShaders to Edit - project setting - Graphics - preloaded shaders", shaderName); - return base.CreateMaterial(i, src, getTexture); + return base.CreateMaterial(i, src); } else { Debug.LogWarningFormat("unknown shader {0}.", shaderName); - return base.CreateMaterial(i, src, getTexture); + return base.CreateMaterial(i, src); } } @@ -97,7 +97,7 @@ namespace VRM } foreach (var kv in item.textureProperties) { - var texture = getTexture(kv.Value); + var texture = Context.GetTexture(kv.Value); if (texture != null) { material.SetTexture(kv.Key, texture.Texture); } diff --git a/UniGLTF b/UniGLTF index 3bc3985f4..1b41b0ab3 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit 3bc3985f4dc04d3d0808a0957675365385893cac +Subproject commit 1b41b0ab306e1be0163d7439354aa3949a5bcf59