babylon.js如何访问其功能之外的网格 [英] babylon.js how to get access to a mesh outside of it's function
本文介绍了babylon.js如何访问其功能之外的网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是无法访问巴比伦网.每当我尝试运行代码时,我都会得到这个错误.
I just cant get access to the babylon mesh. Everytime I try to run the code I get this error.
我尝试了两种不同的方法:
I've tried it with two different approaches:
示例1:
var carTest;
BABYLON.SceneLoader.ImportMesh("", "assets/", "car.obj", scene, function(object) {
carTest = object[0];
});
carTest.position.x = 10;
示例2:
var carTest = BABYLON.SceneLoader.ImportMesh("", "assets/", "car.obj", scene);
carTest.position.x = 10;
推荐答案
如果您知道async/await的概念,则可以使用async函数代替使用带有回调函数的syncn方法.
Instead of using the synchron method with callback function you could use the async function if you know the concept of async / await.
示例:
const data = await SceneLoader.ImportMeshAsync("", "assets/", "car.obj", scene);
const carMeshes = data.meshes;
如果您知道只有一个有孩子,则可以访问[0],否则可能需要合并网格.取决于您要做什么.
If you know there is only one with children you could access [0] otherwise you may need to merger the meshes. Depends on what you want to do.
这篇关于babylon.js如何访问其功能之外的网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文