Skip to content

Commit

Permalink
refactor: Moved all extension names into a static class
Browse files Browse the repository at this point in the history
  • Loading branch information
atteneder committed Oct 14, 2021
1 parent 97553b0 commit d18ac61
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 16 deletions.
31 changes: 31 additions & 0 deletions Runtime/Scripts/Extensions.cs
Original file line number Diff line number Diff line change
@@ -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 {

/// <summary>
/// Collection of glTF extension names
/// </summary>
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";
}
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/Extensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 14 additions & 16 deletions Runtime/Scripts/GltfImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> supportedExtensions = new HashSet<string> {
#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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit d18ac61

Please sign in to comment.