For all loaders, how to set synchronized mode?

Hello all,

For all loaders, the loader.load is asynchronous. How to change to synchronous?

var loader = new THREE.STLLoader();
loader.load( file, function ( geometry ) {
currentObj = geometry;
$( “#loading_data” ).hide();
} );

Synchronous HTTP requests are deprecated in web browsers, and not supported by any three.js loaders. In addition, some loaders have to do asynchronous work other than the HTTP request. See:

If you want to write code without relying on callbacks, consider the new loadAsync method:

(async () => {
  const result = await loader.loadAsync( url );
  console.log( result );

It’s still asynchronous (hence the name) but may be easier to read/write using the new JavaScript async/await API:

1 Like