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 函数代替带有回调函数的同步方法.
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屋!
查看全文