private static IEnumerable <(SubAssetKey, TextureDescriptor)> EnumerateAllTextures(GltfData data, glTF_VRM_extensions vrm)
        {
            // Materials
            for (var materialIdx = 0; materialIdx < data.GLTF.materials.Count; ++materialIdx)
            {
                var material    = data.GLTF.materials[materialIdx];
                var vrmMaterial = vrm.materialProperties[materialIdx];

                if (vrmMaterial.shader == VRM.glTF_VRM_Material.VRM_USE_GLTFSHADER)
                {
                    // Unlit or PBR
                    foreach (var kv in GltfPbrTextureImporter.EnumerateAllTextures(data, materialIdx))
                    {
                        yield return(kv);
                    }
                }
                else
                {
                    // MToon など任意の shader
                    foreach (var kv in VRMMToonTextureImporter.EnumerateAllTextures(data, vrm, materialIdx))
                    {
                        yield return(kv);
                    }
                }
            }

            // Thumbnail
            if (TryGetThumbnailTexture(data, vrm, out var thumbnail))
            {
                yield return(thumbnail);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// glTF 全体で使うテクスチャーを列挙する
        /// </summary>
        private static IEnumerable <(SubAssetKey, TextureDescriptor)> EnumerateAllTextures(GltfData data)
        {
            if (!UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(data.GLTF.extensions, out UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm))
            {
                throw new System.Exception("not vrm");
            }

            // Textures referenced by Materials.
            for (var materialIdx = 0; materialIdx < data.GLTF.materials.Count; ++materialIdx)
            {
                var m = data.GLTF.materials[materialIdx];
                if (UniGLTF.Extensions.VRMC_materials_mtoon.GltfDeserializer.TryGet(m.extensions, out var mToon))
                {
                    foreach (var(_, tex) in Vrm10MToonTextureImporter.EnumerateAllTextures(data, m, mToon))
                    {
                        yield return(tex);
                    }
                }
                else
                {
                    // Fallback to glTF PBR & glTF Unlit
                    foreach (var tex in GltfPbrTextureImporter.EnumerateAllTextures(data, materialIdx))
                    {
                        yield return(tex);
                    }
                }
            }

            // Thumbnail Texture referenced by VRM Meta.
            if (TryGetMetaThumbnailTextureImportParam(data, vrm, out (SubAssetKey key, TextureDescriptor)thumbnail))
            {
                yield return(thumbnail);
            }
        }