Jump to content

return data from BABYLON.SceneLoader.ImportMesh


Gamerazor
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...