0

I have a simple question. How to pass dynamic number to loader manager? Thanks!

var manager = new THREE.LoadingManager();
var loader = new THREE.TextureLoader();

for(var i=0; i<3; i++){
    loader.load(url[i], function ( texture ) {
        console.log(i)
        textures[i] = texture;
    });
}

// console.log(i)  ->  3, 3, 3
// i need          ->  0, 1, 2
wyy
  • 515
  • 2
  • 4
  • 18

1 Answers1

1

If using ecmascript 2015 is an option, just ùse the keyword let instead of var in the for loop:

for(let i=0; i<3; i++){
    ...
}

This will allow the variable i to be block scoped instead of function scoped.

Explanation to ths behaviour can be found in this answer

Community
  • 1
  • 1
micnil
  • 4,705
  • 2
  • 28
  • 39