我正在尝试使用 SceneLoader.ImportMesh
导入网格功能,但是,当我尝试使用 scenes.meshes
访问所有网格时,尽管我能够看到场景中的物体,但唯一出现的是地面。在阅读 SceneLoader 的文档后,我认为 ImportMesh 函数会在场景中导入网格,那么为什么我无法在 SceneLoader 数组中看到它们?
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;
})
}
最佳答案
ImportMesh 是异步函数。
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
要将其用作同步功能,请改用导入网格异步方法。
关于javascript - 导入场景后无法检索所有网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68379785/