var manager = new THREE.LoadingManager();
manager.onStart = function ( url, itemsLoaded, itemsTotal ) {
console.log( 'Started loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
};
manager.onLoad = function ( ) {
console.log( 'Loading complete!');
};
manager.onProgress = function ( url, itemsLoaded, itemsTotal ) {
console.log( 'Loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
};
manager.onError = function ( url ) {
console.log( 'There was an error loading ' + url );
};
var loader = new THREE.OBJLoader( manager );
loader.load( PATH_TO_MY_OBJ, function ( object ) {
console.log("ADD IT");
} );
During the loading phase, the entire canvas freezes. This is a really big problem as I am loading models in on the fly – which locks up and makes the client lag.
How do I fix? I tried promises, they also didn’t work… HELP!
See for reference:
You can see the problem here: three.js webgl - OBJLoader2 usage options – if you load the page and try scrolling as the models load, you will notice a small lag – how to solve? Actually this could be the answer… there is a small 0.1 second lag… which is awful.
Using glTF instead of OBJ will eliminate a considerable amount of the parsing time. But even if you reduce the parsing overhead via glTF, there are other factors which influence the mentioned delay when rendering an asset for the first time. Especially the texture upload and the shader program compilation will cause overhead and thus large frame times. You can mitigate this overhead in various ways. The usage of ImageBitmap or texture compression is one option to speed up the texture upload.
However, I recommend you start with glTF and see how satisfying the performance will be.
BTW: Using promises does not help to unblock the main thread. It’s just a more elegant option for asynchronous programming.