GLTFLoader can't load webp images in webworker
Description
A GLTFLoader created in a webworker can't load webp files. The issue stems from attempting to use Image in a webworker, which doesn't exist.
Reproduction steps
- Run a gtlfloader in a webworker
- Load a gltf that includes a web file
- Error message
Version
r167
Failing in the detectSupport method in GLTFLoader
I Also believe its broken for GLTFTextureAVIFExtension but I don't use that.
But a png and/or jpg works?
@mrdoob Yes, because detectSupport() is only used in context of the WebP and AVIF glTF extension. The detectSupport() implementations have a dependency to Image which is not available in a web worker.
I wonder if detectSupport() of GLTFTextureWebPExtension and GLTFTextureAVIFExtension can be rewritten based on ImageBitmap which should solve the issue.
Small PRs fixing issues with using GLTFLoader in Web Workers, Node.js, or Deno are welcome. Some complex adaptations to other runtime environments might be out of scope for three.js, and would need to be handled at the application level, or by forking the loader. I'm happy to review PRs, but unless someone has bandwidth to work on support for these environments (I do not) I'd prefer to close the issue.
In detectSupport simply resolving true if there is no globalThis.Image allows the GLTFLoader to finish loading in nodejs or webworkers. There are no sid-eeffects here since you can't render the texture anyway.
Perhaps more importantly, the GLTFLoader doesn't actually bubble this error back up to the loader so in user land it just seems like its loading forever.
Also WebP support is at 98% now, so this detectSupport is almost redundant.