Skip to content Skip to sidebar Skip to footer

Three.js Load Multiple Objects Asynchronous Issue

am loading multiple models on the same time to a scene, but it fails to load all the models, it only loading one model on the scene For example am having a building scene with the

Solution 1:

The problem are the globals.

Here a nice reading about Why is Global State so Evil?.

update

I played around a bit with a code similar to your, and I see now what could be what it seem a problem, but it isn't really, you can use an approach like this:

/* object declaration and initialization on load completed */var model1;
load_file('object1', function(model) {
   model1 = model;
   model1.position.x = -2;
});
... 
functionlaad_file(file, on_load_complete) {
   ...
   loader.load("http://localhost/"+file+".js",  function(geometry, object_material)  {
      ...
      scene.add(model);
      /* call the callback to initialize your object */if (on_load_complete !== undefined)
         on_load_complete(model);
   });
   ...
}

render() {
   ...
   if (model1 !== undefined) 
      model1.rotation.x += 0.1;
   ...
}

Solution 2:

Seems like your problem is that renderer not firing after model added to the scene. Try to call it after model added to the scene at your callback function:

scene.add(model); 
renderer.render(scene, camera);

Post a Comment for "Three.js Load Multiple Objects Asynchronous Issue"