I load several car models using a loop in THREE.js, but the problem is that once it loads all objects, but for a while it does not load all objects. For example, if a loop has 3 iterations, it will load 2 objects sometime, sometime it loads 1 and sometime it loads all three objects. I do not know why? I searched a lot, but did not find anything 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 that, another bootloader in which I have the functions init() and animate()
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);
This works fine, but cannot figure out what the problem is with the previous one.
source share