I imported a mesh but the problem is that I need to set its position and rotation in real time. Either controlled by the player with the keyboard or set by an external source.
How does it work? So I import the mesh and then store it in a variable and then acces the mesh using the variable?
As for your question how to control the mesh I’ll try to explain how it is going.
You import you model (usually it is not just one mesh, but a bunch of them). Depending on your needs you may import it with simple standard function, with Asset Container, with Task Manager, with promises etc. All these ways are described in Documentation.
After you import the model, you’ll need to find its Transform node in order to transform it - change position, scaling and rotation of the whole model. Here is small example how to do it - https://playground.babylonjs.com/#05Q46H#11
BABYLON.SceneLoader.ImportMesh("", "scenes/", "skull.babylon", scene, function (newMeshes) {
// Set the target of the camera to the first imported mesh
camera.target = newMeshes[0];
newMeshes[0].position.x = -20;
newMeshes[0].scaling.y = 2;
newMeshes.rotation.z = 1.2; });
So, the function variable newMeshes[0] gets the Transform node (or root node). Actually here newMeshes is a simple array, so you will be able to find all other meshes of your model with the help of this variable.
These are just basics; please search Playground and forum for more examples since this is very popular question. You can also upload your model to Sandbox, open the Inspector and find all nodes of your model with their names, IDs etc.
Here is another example with WASD control and animation - https://www.babylonjs-playground.com/#15EY4F#15
If you want to use it outside this function, you may use, for example scene.getMeshByName ("test").position.y +=0.01;
But you must be sure that your mesh was loaded before you call it, otherwise it will not work. In this case I would recommend to use Asset Manager or Task Manager.
You’ll find more functions for mesh calling at Scene | Babylon.js Documentation
You want to await the call to ImportMeshAsync (important you use the async function here as it is promise-based rather than callback-based). Afterwards, you can freely call scene.getMeshByName.
Make sure to make the calling function as async as you cannot use await from a synchronous function.