-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Add support for extending GLTF with more texture formats and support WebP #76895
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked LGTM but needs wide review :)
To add color to the JPG -> PNG -> Godot texture format note. I think that JPG -> PNG is a lossless conversion, while JPG -> JPG is not, as I was not aware of a way to lossless encode jpg. I think it's theoretically possible to lossless encode JPG -> JPG. It should be possible to directly byte array copy to the filesystem from the gltf buffer which is preferred. The extension is guessed from the required mime type. JPG -> WEBP can also be a lossless conversion, but JPG -> WEBP can also be a narrowing conversion (do not like narrowing conversions). |
So removing it means extension writers will overwrite generation wise every time it processes the images. I prefer to keep it. |
What was changed? |
@fire I updated the PR to re-add
Yeah that's the idea (for a future PR). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comments on my first pass of review.
Thanks! |
This PR improves the GLTF importer by allowing extensions to add support for image and texture formats. This PR also adds support for WebP importing via
EXT_texture_webp
as an example to prove that it works, and since WebP support is already a part of Godot it's pretty simple to say this should be core.These same extension hooks can be used to implement other formats, so #76572 can be updated after this PR is merged to use this API. This also gives us the option to have KTX be an extension in the asset library instead of core. I don't have an opinion of whether it should be core or not, but regardless this extension system is cleaner.
Two new methods have been added to GLTFDocumentExtension:
_parse_image_data
: Passes in the image bytes and MIME type as parameters, which can be used to import an image by setting data of the Image passed into ther_image
return parameter._parse_texture_json
: Passes in the texture JSON, which can be used to set the parameters of the GLTF texture.Some notes and changes to GLTFDocument:
I removedVector<Ref<Image>> source_images;
since it was unnecessary. It was not used consistently, and only read in one place, which I have replaced with just readingVector<Ref<Texture2D>> images;
_parse_image_bytes_into_image
and_parse_image_save_image
methods used to be inside of_parse_images
, but that method was very long and hard to read, so I split it up. This isn't strictly necessary for adding support for more texture formats but it significantly helps with readability..png
, regardless of what was actually contained in the GLTF file (so a GLTF file with a JPEG will save a.png
when extracting). I asked @fire about this and he does not think it's a problem. Even if we want to change this, it could wait for another PR, I just wanted to make a note here in case people are wondering why a GLTF using WebP is placing.png
on the file system.Test project (includes both PNG and WebP, stored as embedded, separate, and base64): gltf-webp-import-test.zip
This work was sponsored by The Mirror.