user5515
user5515

Reputation: 321

How can I load multiple textures asynchronously with a callback in three.js?

Loading a single texture with a callback is easy, eg:

var loader = new THREE.TextureLoader();
var texture1 = loader.load("https://i.imgur.com/UiTMJzv.png", process);

//called only after texture1 is loaded
function process(){

}

The question is how can I load multiple textures asynchronously (and not sequentially) and only call a processing function when all have been loaded?

Upvotes: 0

Views: 609

Answers (1)

Mugen87
Mugen87

Reputation: 31026

You can use THREE.LoadingManager for this:

var manager = new THREE.LoadingManager( function() {

    // this onLoad callback is executed when both textures are loaded

} );

var loader = new THREE.TextureLoader( manager );
var texture1 = loader.load( 'texture1.png' );
var texture2 = loader.load( 'texture2.png' );

Upvotes: 3

Related Questions