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!
well there is a more generic way then what WestLangley proposes.
loader.load( "mesh1.js", meshloader("mesh1.js"));
loader.load( "mesh2.js", meshloader("mesh2.js"));
then
function meshloader(fileName){
return function(geometry){
...
}
}
This way, you can add a identifier on each loaded file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With