4

I am trying to import meshes using SceneLoader.ImportMesh function, however, when I try to access all meshes using scenes.meshes, the only one that appears is ground, despite me being able to see the objects in the scene. After reading documentation on SceneLoader I thought ImportMesh function imports meshes in the scene, so why am I not able to see them in scenes.meshes array?

        var loadMeshes = function(name, filename, x) { 
                BABYLON.SceneLoader.ImportMesh('', "path", filename, scene, function (meshes) {
                        var mesh = meshes[0];
                        mesh.position = new BABYLON.Vector3(x, 5, 5) ;
                        mesh.name = name;
                })
        }
BrownPanther
  • 153
  • 6

1 Answers1

0

ImportMesh is async function.

        var loadMeshes = function(name, filename, x) { 
                BABYLON.SceneLoader.ImportMesh('', "path", filename, scene, function (meshes) {
                        var mesh = meshes[0];
                        mesh.position = new BABYLON.Vector3(x, 5, 5) ;
                        mesh.name = name;
                        console.log(scene.meshes) // you can console log meshes
                })
        }
        loadMeshes()
        console.log(scene.meshes) // you'll get nothing here

to use it as syncronous function, use ImportMeshAsync Method instead.

nakzyu
  • 206
  • 1
  • 7