THREE.js JSONLoader callback

Viewed 4998

In THREE.js, if I have multiple calls to the JSONLoader to load multiple objects like this (simplified example):

function init() {    
  var loader = new THREE.JSONLoader();    
  loader.load("mesh1.js", createScene);    
  loader.load("mesh2.js", createScene);
}    

function createScene( geometry ) {    
  if (geometry.filename == "mesh1.js") {    
    mesh1 = new THREE.Mesh( geometry, material );
    scene.add( mesh1 );    
  } else if (geometry.filename == "mesh2.js") {    
    mesh2 = new THREE.Mesh( geometry, material );
    scene.add( mesh2 );
  }
}

How can I determine which mesh has been returned on callback, especially when they frequently arrive out of order?

I'm trying to handle multiple returned meshes with a single generic callback function. Is there some property in the returned geometry that indicates the original filename that I can test against?

Or perhaps there's a more elegant way? Perhaps creating a new THREE.JSONLoader object for each call would help the callback function determine which mesh has arrived?

I appreciate any help/ideas! Thanks!

2 Answers
Related