javascript - 在 Three.js 中使用 FBXLoader 将 BufferGeometry 转换为 Geometry
问题描述
这是我加载 .fbx 对象的代码,它默认加载一个对象BufferGeometry
:
var loader = new THREE.FBXLoader();
async function loadFiles(scene,props) {
const {files, path, childName, fn} = props;
if (index > files.length - 1) return;
loader.load(path+files[index], object => {
// apply functions / transformations to obj
let sceneObj = fn.call(null,object,props);
if (sceneObj) { scene.add(sceneObj) }
// add obj to scene and push to array
scene.add(object);
objects.push(object);
// if there is another object to load, load it
index++;
loadFiles(scene,props);
});
}
我想用它var geometry = new THREE.Geometry().fromBufferGeometry( bufferGeometry );
来解决这个问题,但我似乎没有mesh
在我的加载器函数中构建一个,所以我看不到如何实现这段代码。
我想以一种可读的方式访问对象的顶点,这就是为什么我不希望它加载为BufferGeometry
.
解决方案
加载器返回一个对象,该对象将包含具有几何图形的网格。您需要遍历对象及其子对象并在遇到它时转换 BufferGeometry。以下是如何实现这一目标的想法:
loader.load(path+files[index], object => {
// iterate over all objects and children
object.traverse(child => {
// convert the buffer geometry
if (child.isMesh && child.geometry.isBufferGeometry) {
const bg = child.geometry;
child.geometry = (new THREE.Geometry()).fromBufferGeometry(bg);
}
});
// ... do something with the loaded model...
});
希望有帮助!
推荐阅读
- python - 我可以模糊 qwidget “menu_pos_” 后面的背景吗?
- flutter - 如何在颤动中禁用 Cupertinopicker?
- mysql-workbench - 错误代码:1582。调用本机函数“SUBSTRING_INDEX”时的参数计数不正确
- azure-pipelines - 天蓝色管道中 timeoutInMinutes 的条件
- python - 使用 repath 参数的 Django url 调度程序
- python - 有没有办法让程序暂停一段时间但仍然有另一段代码在运行?
- python - Split-Apply-Combine 聚合 Pandas 数据框中的行
- javascript - 在另一个js文件中导入axios
- java - 等待方法响应而不阻塞其他HTTP请求的过程
- c# - 停止屏幕截图,包括 Windows 10 的 UWP 应用上的弹出窗口