mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-08 20:08:53 -05:00
Merge pull request #1683 from ousttrue/fix/mime_from_uri
image.uri から mime を決定する
This commit is contained in:
@@ -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<byte> 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user