I am loading multiple car models using a loop in THREE.js, but the problem is that sometime it loads all the objects but some time it does not load all the objects. For example if the loop is of 3 iteration, it will load 2 objects sometime, sometime it loads 1 and sometime it loads all three objects. I don't know why? I searched a lot but can't find any thing useful. Here is the code.
for (var k = 1; k <= myWorld.noOfEnemies(); k++) {
myWorld.setWorldEnemyCar(k);
loader2.load('obj/us/us_police_car.dae', function colladaReady(collada) {
object3 = collada.scene;
object3.scale.x = object3.scale.y = object3.scale.z = 2;
object3.updateMatrix();
object3.position.x = myWorld.enemyCar.position.x;
object3.position.y = myWorld.enemyCar.position.y;
object3.position.z = myWorld.enemyCar.position.z;
object3.rotation.x = -(Math.PI / 2);
object3.rotation.z = (Math.PI / 2);
enemyModels.push(object3);
//localObject.rotation.z = -(Math.PI / 2);
//collidableMeshList3 = localObject;
//console.log(collidableMeshList3);
// init();
// animate();
});
}
After this one more loader in which I have init() and animate() functions
loader2.load('obj/us/us_police_car.dae', function colladaReady(collada) {
localObject = collada.scene;
localObject.scale.x = localObject.scale.y = localObject.scale.z = 2;
localObject.updateMatrix();
localObject.position.x = 0;
localObject.position.y = 0;
localObject.position.z = 0;
localObject.rotation.x = -(Math.PI / 2);
localObject.rotation.z = (Math.PI / 2);
//localObject.rotation.z = -(Math.PI / 2);
//collidableMeshList3 = localObject;
//console.log(collidableMeshList3);
//scene.add(localObject);
init();
animate();
});
This works fine, but can't figure out what the problem with the above one.