【问题标题】:Converting BufferGeometry to Geometry with FBXLoader in Three.js在 Three.js 中使用 FBXLoader 将 BufferGeometry 转换为 Geometry
【发布时间】:2019-06-01 15:28:20
【问题描述】:

这是我加载 .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

【问题讨论】:

    标签: javascript three.js geometry buffer-geometry


    【解决方案1】:

    加载器返回一个对象,该对象将包含具有几何图形的网格。您需要遍历对象及其子对象并在遇到它时转换 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...
    
    });
    

    希望有帮助!

    【讨论】:

    • 这似乎有效,但是在查看更新的顶点之后,它似乎仍然显示我的对象有 1848 个顶点,而它应该只有 310 个。这个方法是否也更新了顶点数组?谢谢。
    • 如果没有看到您正在使用的几何图形,就很难说。你如何计算顶点? fromBufferGeometry 上的文档提到您可能会遇到重复的顶点,并且可以调用 mergeVertices 来删除它们:threejs.org/docs/#api/en/core/Geometry.fromBufferGeometry
    猜你喜欢
    • 2016-01-22
    • 2020-07-11
    • 2013-08-18
    • 2020-09-22
    • 2016-07-26
    • 2018-06-02
    • 2016-09-09
    • 2018-10-06
    • 2015-04-01
    相关资源
    最近更新 更多