How do I get a reference to a mesh after loading it?

I’m loading an obj with the following:

BA.SceneLoader.Append("./models/", "ship.obj", scene, (scene) => {
    // do something with the scene
});

but how do I store the mesh in a variable so I can change its position, etc?

Hi @Kochab and welcome to the forum.

// do something with the scene
for(var mesh of scene.meshes) {
mesh.position = …
}

1 Like

Hi @Arte, thanks. That works to change the position, but I’d also like to store the mesh I just added to a variable so I can refer to it outside of that callback. Given a scene can have many meshes, how do I know when I get to the mesh I’m looking for?

I think I found what I needed, which was a different way of importing:
BA.SceneLoader.ImportMesh("ship", "./models/", "ship.obj", scene);

And then I can refer to it by name:
let ship = scene.getMeshByName("ship");

2 Likes

Thank you, Kochab! I was also having trouble figuring out how to refer to a particular mesh in a Blender-generated scene, trying to bend over backwards to make my script more complex than it needed to be. Your simple solution worked for me right away. :smiley:

1 Like