Interaction with imported models

documentation

#1

Hello , i imported an .obj file to my Js file , but i dont know how to interacte with it , can someone help me please?

i use this code :

var abc = BABYLON.SceneLoader.Append("./", “3dmodel.obj”, scene, function (scene) { });

scene.registerBeforeRender(function () { abc.rotation.y += 0.01; });

Thanks


#2

To load with one mesh in specific, try the ImportMesh loader:

https://www.babylonjs-playground.com/#JUKXQD#0

    BABYLON.SceneLoader.ImportMesh("", "scenes/", "skull.babylon", scene, function (newMeshes) {
        // newMeshes[0] is the mesh to play with
        let skull = newMeshes[0];
        skull.position.x = 0.123456789
    });

Btw you can still play with the meshes with your current syntax. I haven’t used it, but my guess is that it’ll be in the scene.meshes array.


#3

Thanks it is working !!

I have another question if it is possible , there is away to use the skull variable outside the BABYLON.SceneLoader.ImportMesh ? When i used it outside i have a console error : skull it is not defined .


#4

it is possible but only if you wait for the load to be done. Loading a file is asynchronous so you cannot immediately use the mesh after calling ImportMesh (hence the callabck function)