question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GLTFLoader: Doesn't work in Web Worker

See original GitHub issue
Description of the problem

I have been using GLTFLoader with DracoLoader to load my GLTF model and it simply doesn’t without hacks.

There are errors that I have dealt with:

Partially related to https://github.com/mrdoob/three.js/issues/15556

Three.js version
  • Dev
  • r113
Browser
  • [] All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • [] All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, …)

Any device that supports https://caniuse.com/#feat=offscreencanvas I am testing on my Pixel 4XL

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
stickyfingiescommented, Aug 24, 2022

Unless you are also rendering in the Web Worker, with OffscreenCanvas, in which case using GLTFLoader in the same Worker makes sense.

Specifically, serializing scene data (images, geometries, materials) from the main thread --> render thread is possible but impractically slow. Getting images across the CPU border means:

  1. load GLTF model on the main thread
  2. for all textures, render them to an html canvas
  3. extract canvas data with getImageData()
  4. transfer the image data via postMessage() to the render thread
  5. finally, reconstruct the images using a DataTexture in the render thread.

Somewhere during this process, readPixels() is called to extract the texture data. On integrated GPU systems (Intel Core i7), moving this memory around isn’t a big problem. On dedicated devices, however (NVidia GTX 1650) the readPixels() operation takes orders of magnitude longer (I presume this is because texture data must pass through PCI).

In this context, being able to load .gltf models directly from a worker thread is incredibly invaluable, as there is no longer any need for this crazy image (de)serialization bullshit 😆

@donmccurdy @takahirox @mrdoob I’ll ping you in small PRs that fix references to resources not available in Web Workers, e.g. window → self.

1reaction
takahiroxcommented, Feb 27, 2020

In addition to them, I think the following line in .loadTexture() can cause an error because of no window in workers.

var URL = window.URL || window.webkitURL;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Web workers for loading object in three.js - javascript
I was wondering what the best way to load the file would be without locking the UI. I imagine the solution is based...
Read more >
Performance ideas (loading objects in workers, faster ...
Getting things like ColladaLoader and GLTFLoader to function in a web Worker is not too difficult: it requires mocking (or polyfilling) some ...
Read more >
Trying glTF loader with workers on Three.js. ...
Trying glTF loader with workers on Three.js. ... Using web workers for parsing is one of the #1 best things we can do...
Read more >
Three.js Loading a .GLTF File
const gltfLoader = new THREE.GLTFLoader();; const url = 'resources/models/cartoon_lowpoly_small_city_free_pack/scene.gltf';; gltfLoader.load(url, (gltf) => ...
Read more >
Worker - Web APIs - MDN Web Docs
Chrome Edge Worker Full support. Chrome4. Toggle history Full support. Edge... Worker() constructor Full support. Chrome4. Toggle history Full support. Edge... Support for ECMAScript modules Full...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found