mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
102.69k stars 35.37k forks source link

GLTFLoader can't load webp images in webworker #29065

Closed Noobulater closed 1 week ago

Noobulater commented 3 months ago

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

  1. Run a gtlfloader in a webworker
  2. Load a gltf that includes a web file
  3. Error message image

Version

r167

Noobulater commented 3 months ago

Failing in the detectSupport method in GLTFLoader

I Also believe its broken for GLTFTextureAVIFExtension but I don't use that.

mrdoob commented 3 months ago

But a png and/or jpg works?

Mugen87 commented 3 months ago

@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.

donmccurdy commented 1 week ago

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.