Three.js: Use Loader With WebWorker to load the model, the image disappears

Created on 10 Nov 2020  路  3Comments  路  Source: mrdoob/three.js

Describe the bug

Normally, using GLTFLoader to load the model in js does not cause any problems. But when I use webworker, I use GLTFLoader in the worker to load the model. I found that the model obtained in the onload function lacks pictures. After my analysis, I found that when this piece of picture information was loaded in the FILELoader inside GLTFLoader, it had disappeared in its onload function. The magic is that I can temporarily solve this problem through the onprogress method. I added a load stage judgment to onprogress, and then obtained the correct arraybuffer data from this event.

To Reproduce

Steps to reproduce the behavior:

  1. use webWorker
  2. use GLTFLoader
  3. See error on GLTFLoader.onload()

Code

// code goes here
function initGltf(gltfInfo) {
  new GLTFLoader().load(gltfInfo.url, (e) => {
    //I will get wrong data here
  }, (e) => {
    if (e.loaded === e.total) {
      let data = e.target.response
      //I will get right data here
    }
  })
}

Expected behavior

GLTFLoader.onload function can run well when i use webworker

Screenshots
E780B82CBD181967D9C2B77E923A605F

Platform:

  • Device: [Desktop]
  • OS: [Windows, MacOS,]
  • Browser: [Chrome, Firefox]
  • Three.js version: [dev, r0.122.0]
Help (please use the forum)

Most helpful comment

At least with latest Chrome, GLTFLoader should use ImageBitmapLoader for loading textures. Unlike TextureLoader, ImageBitmapLoader does work in a worker. It also has no dependency to FileLoader. Hence, I'm a bit irritated why you are mentioning this:

I found that when this piece of picture information was loaded in the FILELoader inside GLTFLoader

Independently, there is no official web worker support for GLTFLoader, see https://github.com/mrdoob/three.js/issues/15090#issuecomment-431463709.

All 3 comments

At least with latest Chrome, GLTFLoader should use ImageBitmapLoader for loading textures. Unlike TextureLoader, ImageBitmapLoader does work in a worker. It also has no dependency to FileLoader. Hence, I'm a bit irritated why you are mentioning this:

I found that when this piece of picture information was loaded in the FILELoader inside GLTFLoader

Independently, there is no official web worker support for GLTFLoader, see https://github.com/mrdoob/three.js/issues/15090#issuecomment-431463709.

At least with latest Chrome, GLTFLoader should use ImageBitmapLoader for loading textures. Unlike TextureLoader, ImageBitmapLoader does work in a worker. It also has no dependency to FileLoader. Hence, I'm a bit irritated why you are mentioning this:

I found that when this piece of picture information was loaded in the FILELoader inside GLTFLoader

Independently, there is no official web worker support for GLTFLoader, see #15090 (comment).

I am sorry for my analysis, maybe there are some errors.I don't have a deep understanding of the source code. But the phenomenon I mentioned above does exist, how should I solve it.Can you help me ?

@misitetong Please use the forum for help requests. You can login with your GitHub account.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seep picture seep  路  3Comments

ghost picture ghost  路  3Comments

zsitro picture zsitro  路  3Comments

scrubs picture scrubs  路  3Comments

clawconduce picture clawconduce  路  3Comments