代码之家  ›  专栏  ›  技术社区  ›  qbuffer

将BufferGeometry转换为使用FBXLoader的三种几何体。js

  •  0
  • qbuffer  · 技术社区  · 6 年前

    这是我的代码来加载一个。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 在我的加载器函数中,所以我不知道如何实现这段代码。

    我想以可读的方式访问对象的顶点,这就是为什么我不想将其加载为 缓冲几何 .

    1 回复  |  直到 6 年前
        1
  •  3
  •   Garrett Johnson    6 年前

    加载程序返回一个对象,该对象将包含具有几何体的网格。您需要遍历对象及其子对象,并在遇到它时转换缓冲区几何体。以下是如何实现这一目标的想法:

    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...
    
    });
    

    希望有帮助!