How can I call the BufferGeometryUtils?

Hi!!

I tried to merge two geometries pre-loaded from two PLY files, the console told me should be use the

BufferGeometryUtils.mergeBufferGeometries()

for merge de two geometries into one, but I some problems for call this from the class.

Here is my code

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/ply1.ply"),
 loadPLY("ply/ply2.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);});

but I got this error:

TypeError: "THREE.BufferGeometryUtils is undefined"

How can I fix it?

BufferGeometryUtils is in the examples/js folder, and isn’t included by default in three.js. You can download it and copy it into your project (https://github.com/mrdoob/three.js/blob/dev/examples/js/BufferGeometryUtils.js), or with CommonJS:

const THREE = window.THREE = require('three');
require('three/examples/js/BufferGeometryUtils.js');
THREE.BufferGeometryUtils.foo();
2 Likes

thanks<3

but now a got this error:
TypeError: "mergedGeometry.userData is undefined"

What could be wrong?

I would guess you’ve got a version of BufferGeometryUtils that doesn’t match your version of three.js, are you using the most recent three.js? If that’s not the issue I think you’ll need to share a running demo of the issue.

Your right,

I was using the 92 version of three.js, so I change for the 95 version. But the mesh in the code I can’t see it and the console show me this warning:

THREE.WebGLShader: gl.getShaderInfoLog() vertex 0:2(12): warning: extension 'GL_ARB_gpu_shader5' unsupported in vertex shader

okay, this is a error from firebox browser because I open my projects on google chrome without problems