GLTFLoader + DefaultLoadingManager

Hello,
I can’t get how GLTFLoader relates to DefaultLoadingManager

It looks like DefaultLoadingManager fires the onLoad callback before GLTFLoader finished parsing the scene.
Is it a correct behaviour?

I need the loading manager to fire a custom event when everything is loaded, so my other scripts / functions can use the loaded resources. It used to work ok with OBJloader and PLYLoader, even on large models.

Thanks for te help

This looks like a bug, either in GLTFLoader or LoadingManager. I’m not sure LoadingManager is set up to properly handle multi-file models, or models that require asynchronous parsing, and glTF needs both. OBJ and PLY were probably fine because they’re just a single file.

The (internal) LoadingManager API is:

  • itemStart — called when loader begins downloading a file.
  • itemEnd — called when loader finishes downloading a file. If no other items are pending, calls onLoad.

However, .gltf files progress as:

  1. .gltf JSON manifest downloaded.
  • onLoad is called when it completes
  1. .bin and texture resources are requested
  • onLoad is probably called again?
  1. GLTFLoader asynchronously constructs the scene graph and calls its own onLoad callback

If you only need to know when a particular model finishes, use the loader’s onLoad instead of the LoadingManager’s for now. To have LoadingManager do the right thing, i think we should file a bug.

A simple example where LoadingManager works as intended is:

https://threejs.org/examples/webgl_loader_collada.html

The model consist of the dae file and four textures. LoadingManager.onLoad() fires as soon as all assets are loaded.

1 Like

@donmccurdy yes, I was thinking about an async loading problem, because I tried both a .gltf + .bin and a .glb (single binary file) and DefaultLoadingManager counts the file loaded as soon as gltf inits loading.

I didn’t check GLTFLoader’s own loading manager, but it should default to DefaultLoadingManager, as from reference, so maybe it will give back the same error.
Anyway I have a library of assets (mostly textures and 3d models) and I need to know when the entire library is loaded.

Since using GLTF is not extremely necessary right now, I’ll limit 3D models file format to OBJ and PLY.

Are you going to file an issue on github I can track?

Opened an issue here: https://github.com/mrdoob/three.js/issues/14256

4 Likes