I need to load model in loop, the results I want to achieve is the first model with material[0], the second model with material[1]...
But my results are all models have the final material. I think because when the function create mesh got called so variable "i" is already in the last value.
I came across Closure in loop question, but does not seem to apply.
Any help?
Here the code:
var loader = new THREE.CTMLoader();
var material = [new THREE.MeshLambertMaterial( { color: 0xffaa00 } ),
new THREE.MeshLambertMaterial( { color: 0xffffff } )]
for (i = 0; i < material.length; i++) {
loader.load( "models/ctm/ben.ctm", function( geometry ) {
var mesh = new THREE.Mesh( geometry, material[i] );
scene.add( mesh );
}, { useWorker: true } );
}