From d18ac61b699f47d362746c790b380a14a00d1bc7 Mon Sep 17 00:00:00 2001 From: Andreas Atteneder Date: Thu, 14 Oct 2021 22:32:51 +0200 Subject: [PATCH] refactor: Moved all extension names into a static class --- Runtime/Scripts/Extensions.cs | 31 ++++++++++++++++++++++++++++++ Runtime/Scripts/Extensions.cs.meta | 11 +++++++++++ Runtime/Scripts/GltfImport.cs | 30 ++++++++++++++--------------- 3 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 Runtime/Scripts/Extensions.cs create mode 100644 Runtime/Scripts/Extensions.cs.meta diff --git a/Runtime/Scripts/Extensions.cs b/Runtime/Scripts/Extensions.cs new file mode 100644 index 00000000..bd6e03d1 --- /dev/null +++ b/Runtime/Scripts/Extensions.cs @@ -0,0 +1,31 @@ +// Copyright 2020-2021 Andreas Atteneder +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +namespace GLTFast { + + /// + /// Collection of glTF extension names + /// + public static class Extensions { + public const string DracoMeshCompression = "KHR_draco_mesh_compression"; + public const string MaterialsPbrSpecularGlossiness = "KHR_materials_pbrSpecularGlossiness"; + public const string MaterialsTransmission = "KHR_materials_transmission"; + public const string MaterialsUnlit = "KHR_materials_unlit"; + public const string MeshGPUInstancing = "EXT_mesh_gpu_instancing"; + public const string MeshQuantization = "KHR_mesh_quantization"; + public const string TextureBasisUniversal = "KHR_texture_basisu"; + public const string TextureTransform = "KHR_texture_transform"; + } +} diff --git a/Runtime/Scripts/Extensions.cs.meta b/Runtime/Scripts/Extensions.cs.meta new file mode 100644 index 00000000..9fc2de67 --- /dev/null +++ b/Runtime/Scripts/Extensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ac793cf1802844281bf470f4e5ccbaf0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/GltfImport.cs b/Runtime/Scripts/GltfImport.cs index 69b00035..947f3850 100644 --- a/Runtime/Scripts/GltfImport.cs +++ b/Runtime/Scripts/GltfImport.cs @@ -73,23 +73,21 @@ public class GltfImport : IGltfReadable, IGltfBuffers { public const int DefaultBatchCount = 512; - const string ExtDracoMeshCompression = "KHR_draco_mesh_compression"; - const string ExtTextureBasisu = "KHR_texture_basisu"; const string PrimitiveName = "Primitive"; public static readonly HashSet supportedExtensions = new HashSet { #if DRACO_UNITY - ExtDracoMeshCompression, + Extensions.DracoMeshCompression, #endif #if KTX_UNITY - ExtTextureBasisu, + Extensions.TextureBasisUniversal, #endif // KTX_UNITY - "KHR_materials_pbrSpecularGlossiness", - "KHR_materials_unlit", - "KHR_texture_transform", - "KHR_mesh_quantization", - "KHR_materials_transmission", - "EXT_mesh_gpu_instancing", + Extensions.MaterialsPbrSpecularGlossiness, + Extensions.MaterialsUnlit, + Extensions.TextureTransform, + Extensions.MeshQuantization, + Extensions.MaterialsTransmission, + Extensions.MeshGPUInstancing, }; enum ChunkFormat : uint @@ -621,12 +619,12 @@ bool CheckExtensionSupport (Root gltfRoot) { var supported = supportedExtensions.Contains(ext); if(!supported) { #if !DRACO_UNITY - if(ext==ExtDracoMeshCompression) { + if(ext==Extensions.DracoMeshCompression) { logger?.Error(LogCode.PackageMissing,"DracoUnity",ext); } else #endif #if !KTX_UNITY - if(ext==ExtTextureBasisu) { + if(ext==Extensions.TextureBasisUniversal) { logger?.Error(LogCode.PackageMissing,"KtxUnity",ext); } else #endif @@ -642,12 +640,12 @@ bool CheckExtensionSupport (Root gltfRoot) { var supported = supportedExtensions.Contains(ext); if(!supported) { #if !DRACO_UNITY - if(ext==ExtDracoMeshCompression) { + if(ext==Extensions.DracoMeshCompression) { logger?.Warning(LogCode.PackageMissing,"DracoUnity",ext); } else #endif #if !KTX_UNITY - if(ext==ExtTextureBasisu) { + if(ext==Extensions.TextureBasisUniversal) { logger?.Warning(LogCode.PackageMissing,"KtxUnity",ext); } else #endif @@ -952,7 +950,7 @@ void LoadTexture( int index, Uri url, bool nonReadable, bool isKtx ) { } ktxDownloadTasks.Add(index, downloadTask); #else - logger?.Error(LogCode.PackageMissing,"KtxUnity",ExtTextureBasisu); + logger?.Error(LogCode.PackageMissing,"KtxUnity",Extensions.TextureBasisUniversal); Profiler.EndSample(); return; #endif // KTX_UNITY @@ -1674,7 +1672,7 @@ async Task Profiler.EndSample(); await deferAgent.BreakPoint(); #else - logger?.Error(LogCode.PackageMissing,"KtxUnity",ExtTextureBasisu); + logger?.Error(LogCode.PackageMissing,"KtxUnity",Extensions.TextureBasisUniversal); #endif // KTX_UNITY } else { Profiler.BeginSample("CreateTexturesFromBuffers.ExtractBuffer");