When loading multiple car models using a loop in THREE.js, I've encountered an issue where sometimes all objects load correctly, but other times not all of them load. For instance, if the loop iterates 3 times, it may only load 2 objects at times, while other times it might load just 1 or all three objects. I've searched extensively for a solution, but haven't been able to find anything useful. Here is the code snippet:
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);
});
}
Additionally, there's another loader with init()
and animate()
functions included.
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);
init();
animate();
});
The second piece of code works fine, but the issue with the first one remains unresolved. Hopefully, someone can provide some insight into what might be causing this inconsistency.