Polpatch Posted October 12, 2015 Share Posted October 12, 2015 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? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 12, 2015 Share Posted October 12, 2015 Hello and welcome!!! this is because the ImportMesh functions is asynchronous. Which means that the function returns directly and will be fullfilled afterwards. Polpatch 1 Quote Link to comment Share on other sites More sharing options...
Polpatch Posted October 12, 2015 Author Share Posted October 12, 2015 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) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 12, 2015 Share Posted October 12, 2015 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 Polpatch 1 Quote Link to comment Share on other sites More sharing options...
Polpatch Posted October 13, 2015 Author Share Posted October 13, 2015 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 ImportMeshYeah, 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 GameMonetize 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.