-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
glTF: Fix parsing image data with mimeType
undefined
#42504
Conversation
fixes: #37514 |
The glTF 2.0 spec only makes `mimeType` mandatory for `bufferView` image data, so the previous logic to handle URIs with base64-encoded images could fail if `mimeType` is undefined. The logic was documented and refactored to better handle the spec, notably: - `uri` and `bufferView` are now mutually exclusive, and only the latter fails if `mimeType` is undefined. - `uri` with a file path will now respect the `mimeType` if defined, and thus attempt loading the file with the specified format (even if its extension is not the one expected for this format). So we can support bad extensions (PNG data with `.jpg` extension) or custom ones (PNG data in `.img` file for example). - `uri` with base64 encoded data will infer MIME type from `data:image/png` or `data:image/jpeg` if it was not documented in `mimeType` initially. - `uri` with base64 encoded data, no `mimeType` and `application/octet-stream` or `application/gltf-buffer` will fall back to trying both PNG and JPEG loaders. Fully fixes godotengine#33796 (and fixes up godotengine#42501).
1359300
to
2e99d0b
Compare
I did some additional testing and it seems to work well. I can import the whole https://github.com/KhronosGroup/glTF-Sample-Models repo with one exception: The |
Tested a local cherry-pick on |
Cherry-picked for 3.2.4. |
We should first attempt loading as external files, thus creating a dependency. Loading as a buffer should only be used as fallback to support manually loading as PNG or JPEG depending on the defined mimeType. Fixes godotengine#44309, was a regression from godotengine#42504.
We should first attempt loading as external files, thus creating a dependency. Loading as a buffer should only be used as fallback to support manually loading as PNG or JPEG depending on the defined mimeType. Fixes godotengine#44309, was a regression from godotengine#42504. (cherry picked from commit e268a8e)
The glTF 2.0 spec only makes
mimeType
mandatory forbufferView
image data,so the previous logic to handle URIs with base64-encoded images could fail if
mimeType
is undefined.The logic was documented and refactored to better handle the spec, notably:
uri
andbufferView
are now mutually exclusive, and only the latter failsif
mimeType
is undefined.uri
with a file path will now respect themimeType
if defined, and thusattempt loading the file with the specified format (even if its extension is
not the one expected for this format). So we can support bad extensions (PNG
data with
.jpg
extension) or custom ones (PNG data in.img
file forexample).
uri
with base64 encoded data will infer MIME type fromdata:image/png
ordata:image/jpeg
if it was not documented inmimeType
initially.uri
with base64 encoded data, nomimeType
andapplication/octet-stream
or
application/gltf-buffer
will fall back to trying both PNG and JPEGloaders.
Fully fixes #33796 (and fixes up #42501).
Fixes #37514.