I have a sample code here:
function foo() {
var useMesh; // ( line1)
BABYLON.SceneLoader.ImportMesh('mesh_name', './', 'mesh.babylon', scene, (meshes, particles, skeletons, animations) => {
useMesh = meshes[0]; // (line 2)
});
useMesh.position.x = 10; // (line 3)
//and so forth (line 4)
}
How can I use the imported mesh as part of the outer scope? The scoping and callback order are lines 1, 3, 4 then 2. I want to use line 2 to execute before line 3 and after are called. What can I use accomplish that?
The reason I am doing that is that I am using imported mesh mixed with programmed meshes (such as BABYLON.MeshBuilder.CreateBox()) in the same function and they will interact together. And, there are multiple ImportMesh that are going to interact with each other in the foo function.
I know this is more of a JavaScript question than a BabylonJS question but it’s puzzling me. I tried to looked it up on StackExchange and Google trying to find hints on how to hoist the scope of the imported with general JavaScript queries but with actual answer. ImportMeshAsync does not work either or maybe I’m not using that right.
Any advice or hints, such as to any tutorials that can lead to my answer?