From 645e254744c8e1174dfaab533bba5b925dd544d7 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Tue, 4 Jun 2024 17:32:43 +0900 Subject: [PATCH] load KHR_texture_basisu as default (but not implemented now) --- .../UniGLTF/IO/ExtensionSupportFlags.cs | 2 +- .../Runtime/UniGLTF/IO/ImporterContext.cs | 16 ---------- .../IO/TextureIO/GltfTextureImporter.cs | 29 +++++++++++++++---- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ExtensionSupportFlags.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ExtensionSupportFlags.cs index e84684e5f..0ae47adb9 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ExtensionSupportFlags.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ExtensionSupportFlags.cs @@ -5,7 +5,7 @@ /// /// KHR_texture_basisu 拡張を考慮するかどうか。 /// - public bool ConsiderKhrTextureBasisu { get; set; } + public bool ConsiderKhrTextureBasisu { get; set; } = true; /// /// ファイルに含まれる "全ての" テクスチャの画像が Y 軸反転しているかどうか。 diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs index cabc59f83..e05d60b09 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -36,7 +36,6 @@ namespace UniGLTF ITextureDeserializer textureDeserializer = null, IMaterialDescriptorGenerator materialGenerator = null) { - TryValidateGltfData(data); Data = data; TextureDescriptorGenerator = new GltfTextureDescriptorGenerator(Data); MaterialDescriptorGenerator = materialGenerator ?? MaterialDescriptorGeneratorUtility.GetValidGltfMaterialDescriptorGenerator(); @@ -75,21 +74,6 @@ namespace UniGLTF "KHR_draco_mesh_compression", }; - /// - /// GltfData をバリデートし、読み込み不可能な問題があれば例外を投げる - /// - private static void TryValidateGltfData(GltfData data) - { - if (data.ExtensionSupportFlags.ConsiderKhrTextureBasisu && !Application.isPlaying) - { - throw new UniGLTFNotSupportedException("KHR_texture_basisu is only available in play mode."); - } - if (data.ExtensionSupportFlags.ConsiderKhrTextureBasisu && !data.ExtensionSupportFlags.IsAllTexturesYFlipped) - { - throw new UniGLTFNotSupportedException("KHR_texture_basisu is only supported with all textures Y-flipped."); - } - } - #region Load. Build unity objects public virtual async Task LoadAsync(IAwaitCaller awaitCaller, Func MeasureTime = null) { diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/GltfTextureImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/GltfTextureImporter.cs index f373dbe01..b5c56298f 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/GltfTextureImporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/GltfTextureImporter.cs @@ -238,13 +238,16 @@ namespace UniGLTF { var texture = data.GLTF.textures[textureIndex]; - if (data.ExtensionSupportFlags.ConsiderKhrTextureBasisu && - glTF_KHR_texture_basisu.TryGet(texture, out var basisuExtension)) + if (glTF_KHR_texture_basisu.TryGet(texture, out var basisuExtension)) { - var basisuImageIndex = basisuExtension.source; - if (basisuImageIndex >= 0 && basisuImageIndex < data.GLTF.images.Count) + // NOTE: 実際に basisu 拡張が存在するとき、ロード設定を確認する。 + if (TryValidateBasisuLoadingSettings(data)) { - return basisuImageIndex; + var basisuImageIndex = basisuExtension.source; + if (basisuImageIndex >= 0 && basisuImageIndex < data.GLTF.images.Count) + { + return basisuImageIndex; + } } } @@ -257,6 +260,22 @@ namespace UniGLTF return default; } + + private static bool TryValidateBasisuLoadingSettings(GltfData data) + { + if (!data.ExtensionSupportFlags.ConsiderKhrTextureBasisu) return false; + + if (data.ExtensionSupportFlags.ConsiderKhrTextureBasisu && !Application.isPlaying) + { + throw new UniGLTFNotSupportedException("KHR_texture_basisu is only available in play mode."); + } + if (data.ExtensionSupportFlags.ConsiderKhrTextureBasisu && !data.ExtensionSupportFlags.IsAllTexturesYFlipped) + { + throw new UniGLTFNotSupportedException("KHR_texture_basisu is only supported with all textures Y-flipped."); + } + return true; + } + private static byte[] ToArray(NativeArray bytes) {