我如何从threejs调用BufferGeometryUtils?

时间:2018-08-13 23:15:19

标签: three.js

我尝试将从两个PLY文件中预加载的两个几何图形合并,浏览器的控制台告诉我应该使用BufferGeometryUtils.mergeBufferGeometries()将两个几何图形合并为一个,但是从课。

这是我的代码:

    var scene = new THREE.Scene(); 
    var singleGeometry, material, mesh;
    var loader = new THREE.PLYLoader();

    function loadPLY(path) {
      return new Promise(resolve => {
        loader.load(path, result => {
           console.log('Success');
            resolve(result);
        });
     });

     }

    init();

   Promise.all([
     loadPLY("ply/Paso_1_mandible.ply"),
     loadPLY("ply/maxila.ply")
   ])
   .then(geometries => {
      geometries.forEach(geometry => geometry.computeVertexNormals());
        singleGeometry = new THREE.BufferGeometry();
        singleGeometry = THREE.BufferGeometryUtils.mergeBufferGeometries(geometries);   

     material = new THREE.MeshPhongMaterial({color: 0x0055ff });
     mesh = new THREE.Mesh(singleGeometry, material);

     mesh.position.y = 1;
     mesh.position.z =  1;
     mesh.position.x = 1;
     mesh.scale.multiplyScalar( 0.0001 );
     mesh.castShadow = true;
     mesh.receiveShadow = true;


    scene.add(mesh);


    })
     .then(() => {
        animate();
    })
    .catch(err => {console.error(err);});

但是我得到了这个错误:

TypeError: "THREE.BufferGeometryUtils is undefined"

这是文档的链接:

class BufferGeometryUtils

2 个答案:

答案 0 :(得分:1)

在三个主发行版的examples / js / BufferGeometryUtils.js中。

https://github.com/mrdoob/three.js/archive/master.zip

答案 1 :(得分:-1)

错误TypeError: "THREE.BufferGeometryUtils is undefined"很明显。

您需要在代码中包含BufferGeometryUtils类/文件。
正如在examples文件夹中一样,它不包含在主Three.js库中。