mrdoob/three.js — Issue #1280: How to position meshes while loading? (async problem)
Author: kalekold
Created: 2012-02-08 20:06:22+00:00
State: open

I have the following code to load and position the same models over and over again. The problem is that all the models are positioned the same. i.e. they are all at {x:6, y:0, z:0}

I'm thinking this is because the loading of the meshes is asynchronous and the loop finishes before the positions are set. How can i enter the positions on mesh load? In other words wait until the mesh has loaded into the scene and then position them?

```javascript

for (var x = 0; x < Models.length; x++)
{
JSONLoader.load("../assets/models/" + Models[x], function(Geometry)
{
Mesh = new THREE.Mesh(Geometry, DarkMaterial);
Mesh.position.set(x, 0, 0);
Scene.add(Mesh);
});
}

```
At the minute i'm doing something uncool like this:

```javascript

for (var x = 0; x < Scene.objects.length; x = x + 2)
{
Scene.objects[x].position.set((x / 2) - 2.5, 0, 0);
Scene.objects[x].rotation.y += 0.01;

Scene.objects[x + 1].position.set((x / 2) - 2.5, -2, 0);
Scene.objects[x + 1].rotation.y += 0.01;
}

```
Any ideas?