// SPDX-FileCopyrightText: 2023 Unity Technologies and the glTFast authors // SPDX-License-Identifier: Apache-2.0 #if DEBUG #define GLTFAST_REPORT #endif using System; using System.Collections.Generic; using UnityEngine; using System.Text; namespace GLTFast.Logging { /// /// Predefined message code /// public enum LogCode : uint { /// /// No or unknown log code. /// None, /// /// Unknown GLTFAccessorAttributeType /// AccessorAttributeTypeUnknown, /// /// Inconsistent accessor usage /// AccessorInconsistentUsage, /// /// glTF file uses certain vertex attributes/accessors across multiple /// meshes! This may result in low performance and high memory usage. /// Try optimizing the glTF file. /// AccessorsShared, /// /// Animation channel has invalid node id /// AnimationChannelNodeInvalid, /// /// Animation channel has invalid sampler id /// AnimationChannelSamplerInvalid, /// /// Invalid animation format /// AnimationFormatInvalid, /// /// Unsupported animation target path /// AnimationTargetPathUnsupported, /// /// Download buffer failed /// BufferLoadFailed, /// /// Invalid main buffer type /// BufferMainInvalidType, /// /// Invalid JSON chunk /// ChunkJsonInvalid, /// /// Incomplete chunk /// ChunkIncomplete, /// /// Unknown chunk type /// ChunkUnknown, /// /// Unsupported color format /// ColorFormatUnsupported, /// /// Download failed /// Download, /// /// Loading embed buffer failed /// EmbedBufferLoadFailed, /// /// Inconsistent embed image type /// EmbedImageInconsistentType, /// /// Loading embedded image failed /// EmbedImageLoadFailed, /// /// Unsupported embed image format /// EmbedImageUnsupportedType, /// /// JSON embed buffers are slow! consider using glTF binary /// EmbedSlow, /// /// glTF extension is not supported /// ExtensionUnsupported, /// /// Image could not get exported /// ExportImageFailed, /// /// Not a glTF-binary file /// GltfNotBinary, /// /// Unsupported glTF version /// GltfUnsupportedVersion, /// /// Invalid hierarchy /// HierarchyInvalid, /// /// Support for Jpeg/PNG texture decoding/encoding is not enabled /// ImageConversionNotEnabled, /// /// Unknown image format /// ImageFormatUnknown, /// /// Have to create copy of image {0} due to different samplers. This is harmless, but requires more memory. /// ImageMultipleSamplers, /// /// Invalid index format /// IndexFormatInvalid, /// /// Parsing JSON failed /// JsonParsingFailed, /// /// Chance of incorrect materials! glTF transmission is approximated /// when using built-in render pipeline! /// MaterialTransmissionApprox, /// /// Chance of incorrect materials! glTF transmission is approximated. /// Enable Opaque Texture access in Universal Render Pipeline! /// MaterialTransmissionApproxUrp, /// /// No bounds for mesh {0} => calculating them. /// MeshBoundsMissing, /// /// Skipping non-readable mesh /// MeshNotReadable, /// /// Image URL missing /// MissingImageURL, /// /// Retrieving morph target failed /// MorphTargetContextFail, /// /// Overriding naming method to be OriginalUnique (animation requirement) /// NamingOverride, /// /// A certain package needs to be installed in order to support a specific glTF extension /// PackageMissing, /// /// Primitive mode is untested /// PrimitiveModeUnsupported, /// /// Remap is not fully supported /// RemapUnsupported, /// /// Shader is missing. Make sure to include it in the build. /// ShaderMissing, /// /// Skin missing /// SkinMissing, /// /// Sparse Accessor not supported /// SparseAccessor, /// /// Download texture failed /// TextureDownloadFailed, /// /// Invalid texture type /// TextureInvalidType, /// /// Texture not loaded /// TextureLoadFailed, /// /// Texture not found /// TextureNotFound, /// /// Could not find material that supports points topology /// TopologyPointsMaterialUnsupported, /// /// Unsupported topology /// TopologyUnsupported, /// /// Unsupported type /// TypeUnsupported, /// /// Support for direct Jpeg/PNG texture download is not enabled /// UnityWebRequestTextureNotEnabled, /// /// Only eight UV sets will get imported /// UVLimit, /// /// UV set index is not supported in current render pipeline /// UVMulti, /// /// Fallback to uncompressed meshes/bufferViews is not supported. /// UncompressedFallbackNotSupported, /// /// Inconsistent use of vertex color attribute. /// InconsistentVertexColorUsage, /// /// Stream read error. /// StreamError, } /// /// Converts to human readable and understandable message string. /// public static class LogMessages { #if GLTFAST_REPORT static readonly string k_LinkProjectSetupTextureSupport = $"See {GltfGlobals.GltfPackageName}/Documentation~/ProjectSetup.md#texture-support for details."; static readonly Dictionary k_FullMessages = new Dictionary() { { LogCode.AccessorAttributeTypeUnknown, "Unknown GLTFAccessorAttributeType" }, { LogCode.AccessorInconsistentUsage, "Inconsistent accessor usage {0} != {1}" }, { LogCode.AccessorsShared, @"glTF file uses certain vertex attributes/accessors across multiple meshes! This may result in low performance and high memory usage. Try optimizing the glTF file. See details in corresponding issue at https://github.com/atteneder/glTFast/issues/52" }, { LogCode.AnimationChannelNodeInvalid, "Animation channel {0} has invalid node id" }, { LogCode.AnimationChannelSamplerInvalid, "Animation channel {0} has invalid sampler id or output" }, { LogCode.AnimationFormatInvalid, "Invalid animation format {0}" }, { LogCode.AnimationTargetPathUnsupported, "Unsupported animation target path {0}" }, { LogCode.BufferLoadFailed, "Download buffer {1} failed: {0}" }, { LogCode.BufferMainInvalidType, "Invalid mainBufferType {0}" }, { LogCode.ChunkJsonInvalid, "Invalid JSON chunk" }, { LogCode.ChunkIncomplete, "Incomplete chunk" }, { LogCode.ChunkUnknown, "Unknown chunk type {0}" }, { LogCode.ColorFormatUnsupported, "Unsupported color format {0}" }, { LogCode.Download, "Download URL {1} failed: {0}" }, { LogCode.EmbedBufferLoadFailed, "Loading embed buffer failed" }, { LogCode.EmbedImageInconsistentType, "Inconsistent embed image type {0}!={1}" }, { LogCode.EmbedImageLoadFailed, "Loading embedded image failed" }, { LogCode.EmbedImageUnsupportedType, "Unsupported embed image format {0}" }, { LogCode.EmbedSlow, "JSON embed buffers are slow! consider using glTF binary" }, { LogCode.ExtensionUnsupported, "glTF extension {0} is not supported" }, { LogCode.ExportImageFailed, "Export image failed" }, { LogCode.GltfNotBinary, "Not a glTF-binary file" }, { LogCode.GltfUnsupportedVersion, "Unsupported glTF version {0}" }, { LogCode.HierarchyInvalid, "Invalid hierarchy" }, { LogCode.ImageConversionNotEnabled, $"Jpeg/PNG textures failed because required built-in packages \"Image Conversion\"/\"Unity Web Request Texture\" are not enabled. {k_LinkProjectSetupTextureSupport}" }, { LogCode.ImageFormatUnknown, "Unknown image format (image {0};uri:{1})" }, { LogCode.ImageMultipleSamplers, "Have to create copy of image {0} due to different samplers. This is harmless, but requires more memory." }, { LogCode.InconsistentVertexColorUsage, "Potential visual discrepancy due to inconsistent vertex colors usage on mesh {0}" }, { LogCode.IndexFormatInvalid, "Invalid index format {0}" }, { LogCode.JsonParsingFailed, "Parsing JSON failed" }, { LogCode.MaterialTransmissionApprox, "Chance of incorrect materials! glTF transmission is approximated when using built-in render pipeline!" }, { LogCode.MaterialTransmissionApproxUrp, @"Chance of incorrect materials! glTF transmission is approximated. Enable Opaque Texture access in Universal Render Pipeline!" }, { LogCode.MeshBoundsMissing, "No bounds on position accessor {0} => calculating them." }, { LogCode.MeshNotReadable, "Skipping non-readable mesh {0}" }, { LogCode.MissingImageURL, "Image URL missing" }, { LogCode.MorphTargetContextFail, "Retrieving morph target failed" }, { LogCode.NamingOverride, "Overriding naming method to be OriginalUnique (animation requirement)" }, { LogCode.PackageMissing, $"{{0}} package needs to be installed in order to support glTF extension {{1}}!\nSee {GltfGlobals.GltfPackageName}/README.md#installing for instructions" }, { LogCode.PrimitiveModeUnsupported, "Primitive mode {0} is untested" }, { LogCode.RemapUnsupported, "{0} remap is not fully supported" }, { LogCode.ShaderMissing, $"Shader \"{{0}}\" is missing. Make sure to include it in the build (see {GltfGlobals.GltfPackageName}/Documentation~/ProjectSetup.md#materials-and-shader-variants )" }, { LogCode.SkinMissing, "Skin missing" }, { LogCode.SparseAccessor, "Sparse Accessor not supported ({0})" }, { LogCode.StreamError, "Stream error: {0}." }, { LogCode.TextureDownloadFailed, "Download texture {1} failed: {0}" }, { LogCode.TextureInvalidType, "Invalid {0} texture type (material: {1})" }, { LogCode.TextureLoadFailed, "Texture #{0} not loaded" }, { LogCode.TextureNotFound, "Texture #{0} not found" }, { LogCode.TopologyPointsMaterialUnsupported, "Could not find material that supports points topology" }, { LogCode.TopologyUnsupported, "Unsupported topology {0}" }, { LogCode.TypeUnsupported, "Unsupported {0} type {1}" }, { LogCode.UncompressedFallbackNotSupported, "Fallback to uncompressed meshes/bufferViews is not supported" }, { LogCode.UnityWebRequestTextureNotEnabled, $"PNG/Jpeg textures load slower because built-in package \"Unity Web Request Texture\" is not enabled. {k_LinkProjectSetupTextureSupport}" }, { LogCode.UVLimit, "Only eight UV sets will get imported" }, { LogCode.UVMulti, "UV set index {0} is not supported in current render pipeline" }, }; #endif /// /// Converts a to human readable and understandable message string. /// /// Input LogCode /// Additional message parts (te be filled into final message) /// Human readable and understandable message string public static string GetFullMessage(LogCode code, params string[] messages) { if (code == LogCode.None) { var sb = new StringBuilder(); if (messages == null) return ""; foreach (var message in messages) { if (sb.Length > 0) { sb.Append(";"); } sb.Append(message); } return sb.ToString(); } #if GLTFAST_REPORT return messages != null // ReSharper disable once CoVariantArrayConversion ? string.Format(k_FullMessages[code], messages) : k_FullMessages[code]; #else if (messages == null) { return code.ToString(); } else { var sb = new StringBuilder(code.ToString()); foreach (var message in messages) { sb.Append(";"); sb.Append(message); } return sb.ToString(); } #endif } #if UNITY_EDITOR internal static string GetRawMessage(LogCode code) { return k_FullMessages[code]; } #endif } }