我在导入的网格体上使用 CSG 时遇到问题,这是我的代码:
var a; var b;
BABYLON.SceneLoader.ImportMesh("", "./public/Models/", "model1.stl", scene, function (newMeshes) {
// Set the target of the camera to the first imported mesh
camera.target = newMeshes[0];
a = newMeshes[0];
});
BABYLON.SceneLoader.ImportMesh("", "./public/Models/", "model2.stl", scene, function (newMeshes) {
// Set the target of the camera to the first imported mesh
//camera.target = newMeshes[0];
b = newMeshes[0];
});
var aCSG = BABYLON.CSG.FromMesh(a);
var bCSG = BABYLON.CSG.FromMesh(b);
“var a”和“var b”未定义,调试告诉我
“BABYLON.CSG:网格类型错误,必须是 BABYLON.Mesh”
有什么方法可以将导入的网格转换为BABYLON.MESH吗?
非常感谢
最佳答案
这是因为 ImportMesh 是异步的,您必须在回调部分移动代码:
BABYLON.SceneLoader.ImportMesh("", "./public/Models/", "model1.stl", scene, function (newMeshes) {
// Set the target of the camera to the first imported mesh
camera.target = newMeshes[0];
a = newMeshes[0];
BABYLON.SceneLoader.ImportMesh("", "./public/Models/", "model2.stl", scene, function (newMeshes) {
// Set the target of the camera to the first imported mesh
//camera.target = newMeshes[0];
b = newMeshes[0];
var aCSG = BABYLON.CSG.FromMesh(a);
var bCSG = BABYLON.CSG.FromMesh(b);
});
});
关于javascript - 将网格导入到 BABYLON.Mesh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51594372/