gpt4 book ai didi

javascript - 将网格导入到 BABYLON.Mesh

转载 作者:行者123 更新时间:2023-12-03 01:24:54 24 4
gpt4 key购买 nike

我在导入的网格体上使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com