three.js icon indicating copy to clipboard operation
three.js copied to clipboard

GLTFLoader can't load webp images in webworker

Open Noobulater opened this issue 1 year ago • 3 comments

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 avatar Aug 05 '24 03:08 Noobulater

Failing in the detectSupport method in GLTFLoader

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

Noobulater avatar Aug 05 '24 04:08 Noobulater

But a png and/or jpg works?

mrdoob avatar Aug 08 '24 03:08 mrdoob

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

Mugen87 avatar Aug 09 '24 11:08 Mugen87

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.

donmccurdy avatar Nov 05 '24 15:11 donmccurdy

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.

ashconnell avatar Mar 28 '25 01:03 ashconnell