Sign in to follow this  
Polpatch

How can I interact with imported Mesh?

Recommended Posts

Hi guys, (I'm so sorry for my English)

 

I'm new in babylon's programming and I'm in trouble.

i'm importing a local Mesh with the method:

 



BABYLON.SceneLoader.ImportMesh("him", "models/Dude/", "dude.babylon", scene, function(newMeshes){
scene.cameras[0].setTarget(newMeshes[0].position);

scene.getMeshByName("him").scaling = new BABYLON.Vector3(0.07, 0.07, 0.07); //this work
});

scene.getMeshByName("him").position +=10; //scene.getMeshByName("him") is null


 

In the function's scope of the argument (function(newMeshes){...}) i can interact with my Mesh (if i inspect the scene i can see it).

 

However out of that function i can't reach it.

How can i interact with this imported mesh?

Share this post


Link to post
Share on other sites

Hello and welcome!!!

 

this is because the ImportMesh functions is asynchronous. Which means that the function returns directly and will be fullfilled afterwards.

You saved my life, thanks a lot!

 

So i can resolve that with a  loop like this:

/*import mesh code*/.../******************/while(scene.getMeshByName("him") == null){}scene.getMeshByName("him").position += 10;

right? (I can't test this now)

Share this post


Link to post
Share on other sites

Yes or even better:

 

BABYLON.SceneLoader.ImportMesh("him", "models/Dude/", "dude.babylon", scene, function(newMeshes){        
        scene
.cameras[0].setTarget(newMeshes[0].position);
        
        scene
.getMeshByName("him").scaling = new BABYLON.Vector3(0.07, 0.07, 0.07); //this work

 

      continueMyCode();
    });
 

Do whatever you want to do in a function called continueMyCode() instead of directely after calling ImportMesh

Share this post


Link to post
Share on other sites

Yes or even better:

 

BABYLON.SceneLoader.ImportMesh("him", "models/Dude/", "dude.babylon", scene, function(newMeshes){        

        scene.cameras[0].setTarget(newMeshes[0].position);

        

        scene.getMeshByName("him").scaling = new BABYLON.Vector3(0.07, 0.07, 0.07); //this work

 

      continueMyCode();

    });

 

Do whatever you want to do in a function called continueMyCode() instead of directely after calling ImportMesh

Yeah, you are right. But Probably I have to interact different mesh between them.

I wanted to understand why I could't find the imported mesh out of that function.

I will use each the way. Thanks again   :lol:

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.