三个 JS 从 Geometry 转换为 BufferGeometry 在加载 PLY 文件时不起作用

THREE JS converting to BufferGeometry from Geometry not working when loading PLY file

我正在从 PLY 文件(超过 60Mb)加载一个非常复杂的 3D 模型。在我的项目中,我需要使用轨道控制围绕物体移动。显然,由于文件很大,某些计算机的操作速度非常慢。为了加快速度,我尝试使用以下代码行将我的几何图形转换为 Buffer 几何图形:

this.loader.load('assets/data/GuyFawkesMask.ply', function (geometry) {
      var bufferGeometry = new THREE.BufferGeometry().fromGeometry( geometry );

      console.log(bufferGeometry);

      // Create object
        let object =
            new THREE.Mesh(bufferGeometry,
            new THREE.MeshPhongMaterial(
                {
                    color: 0xFFFFFF,
                    //vertexColors: THREE.VertexColors,
                    shading: THREE.FlatShading,
                    shininess: 0
                })
            );

        _this.add(object);
    });

但我收到以下错误:

TypeError: Cannot read property '0' of undefined at DirectGeometry.fromGeometry (three.module.js:12219) at BufferGeometry.fromGeometry (three.module.js:14307) at threed-viewer.component.ts:379 at index.js:52 at XMLHttpRequest. (three.module.js:29263) at ZoneDelegate.webpackJsonp.818.ZoneDelegate.invokeTask (zone.js:367) at Object.onInvokeTask (ng_zone.js:264) at ZoneDelegate.webpackJsonp.818.ZoneDelegate.invokeTask (zone.js:366) at Zone.webpackJsonp.818.Zone.runTask (zone.js:166) at XMLHttpRequest.ZoneTask.invoke (zone.js:420)

有什么想法吗?

谢谢,

恐龙

仅发布 prisoner849 评论(作为答案)以供将来参考:

If I get it right, looking into the source code of PLYLoader.js, the geometry, which the callback function returns, is already of THREE.BufferGeometry()