Renaming "__root__" for positioning

I’m loading multiple .glb files into a scene and I’m having trouble position each. Here is an example of my code.

// Append glTF model to scene.
BABYLON.SceneLoader.Append(“http://localhost/assets/”, “gdance.glb”, scene, function (scene) {
// Create a default arc rotate camera and light.
scene.createDefaultCameraOrLight(true, true, true);

    // The default camera looks at the back of the asset.
    // Rotate the camera by 180 degrees to the front of the asset.
    scene.activeCamera.alpha += Math.PI;
    scene.name = "__root-2__";

scene.getMeshByID(“root-2”).position = new BABYLON.Vector3(100, 0, 0);

});

This seems to not work, so how is a good way to rename these to be positioned individually?

Ok so between documentation and some of the forumn posts and some playing around here is a way to position multiple some of the glb files

// Append glTF model to scene.
BABYLON.SceneLoader.Append(“http://localhost/assets/”, “congratulations.glb”, scene, function (scene) {
var root = scene.meshes[3];
root.name = ‘root-3’;
root.id = ‘root-3’;
// Create a default arc rotate camera and light.
scene.createDefaultCameraOrLight(true, true, true);

    // The default camera looks at the back of the asset.
    // Rotate the camera by 180 degrees to the front of the asset.
    scene.activeCamera.alpha += Math.PI;

scene.getMeshByID(“root-3”).position = new BABYLON.Vector3(0, 1000, 0);

});

The scene.meshes[ ] is indexed 0 is the camera 1 is the first model file 2 is the second model file … etc… However I’m not sure how to specifically target the glb file I’m wanting to

So here is a great way to load multiple glb files and position them

BABYLON.SceneLoader.ImportMeshAsync(null, ‘/assets/’, ‘congratulations.glb’, scene).then(results => {
var root = results.meshes[0];
root.name = ‘xyz3’;
root.id = ‘xyz3’;
root.rotation.y = Math.PI; // we’re backwards in import

    root.position = new BABYLON.Vector3(0, 250, 0);
});
3 Likes