Gamerazor Posted June 13, 2015 Share Posted June 13, 2015 how can i return any data from BABYLON.SceneLoader.ImportMesh? for example:BABYLON.SceneLoader.ImportMesh('Box', '../assets/', 'box.babylon', Balltingo, function(newMeshes) { var box, boxClone, col, i, row, separate, x, y, z; box = newMeshes[0]; x = -8; y = 1.9; z = -6; box.position = new BABYLON.Vector3(x, y, z); box.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, { mass: 1000 }); row = 0; boxClone = []; col = 0; i = 0; separate = 2; while (row < 3) { while (col < 4) { z = z + 3; boxClone[i] = box.clone("boxClone" + col); boxClone[i].position = new BABYLON.Vector3(x, y, z); boxClone[i].setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, { mass: 1000 }); boxClone[i].checkCollisions = true; col++; i++; } z = -6; x = x + 4; if (row < 2) { boxClone[i] = box.clone("boxClone" + row); boxClone[i].position = new BABYLON.Vector3(x, y, z); boxClone[i].setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, { mass: 1000 }); boxClone[i].checkCollisions = true; } col = 0; row++; i++; } i = 0; });i want return the boxClone array to use in other functions some example please. Thanks! Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted June 13, 2015 Share Posted June 13, 2015 Import mesh returns immediately, so no formal return possible. You can declare vars like boxclone at a higher level for use else where. I am not a fan of the .babylon load process. The asynchronous nature is what I like the least. You may not have any choice unless you are coming from Blender though. Quote Link to comment Share on other sites More sharing options...
gryff Posted June 14, 2015 Share Posted June 14, 2015 GR, I'm no javascript expert, but looking at your code you seem to be declaring the boxClone variable as a local variable inside the ImportMesh function - can you declare it outside the function as a global variable? As I said though, I'm no expert and maybe the coders here can help cheers, gryff Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 14, 2015 Share Posted June 14, 2015 Hi,Gryff is right, this is one way of doing what you wanted. The minute import mesh will be called, the variable from the higher scope will be initialized.The question is, what do you actually what to do with the data? If you have a function that needs the data, simply call it at the end of the callback (or make it the callback itself). Just one way of many :-)So, we would need some more information to give a proper answer. Gamerazor 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.