diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs index 899c6bde7..3a7527e96 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs @@ -333,6 +333,25 @@ namespace UniGLTF return result; } + static string GuessMimeFromUri(string uri) + { + if (string.IsNullOrEmpty(uri)) + { + return null; + } + var ext = System.IO.Path.GetExtension(uri).ToLowerInvariant(); + switch (ext) + { + case ".png": + return "image/png"; + case ".jpg": + case ".jpeg": + return "image/jpeg"; + default: + return null; + } + } + public (NativeArray binary, string mimeType)? GetBytesFromImage(int imageIndex) { if (imageIndex < 0 || imageIndex >= GLTF.images.Count) return default; @@ -340,11 +359,13 @@ namespace UniGLTF var image = GLTF.images[imageIndex]; if (string.IsNullOrEmpty(image.uri)) { + // use bufferView(glb) return (GetBytesFromBufferView(image.bufferView), image.mimeType); } else { - return (GetBytesFromUri(image.uri), image.mimeType); + // use uri(gltf) + return (GetBytesFromUri(image.uri), image.mimeType ?? GuessMimeFromUri(image.uri)); } }