“TypeError: Cannot read property ‘x’ of undefined” thrown when converting BufferGeometry to Geometry

I have a non-indexed BufferGeometry that I am trying to convert to Geometry so I may compute line distances but I am running into a exception within the three.js code:
image
The BufferGeometry contains a position attribute with a array of 6 values (2 vertices). Seeing that the error is thrown in computeFaceNormals, the problem seems to begin beforehand when the faces I are being added here:
image
Notice that since positions has the length of 6 then this loop will be iterated once, hence adding a face with 3 sides (0,1,2); however since there is only 2 vertices then the third vertex is undefined when being used here:
image

With vC being undefined, it later throws the error in subVectors function where it tries to grab the x value of the first parameter.

Please help.

Author: Fantashit

1 thought on ““TypeError: Cannot read property ‘x’ of undefined” thrown when converting BufferGeometry to Geometry

  1. Is this to say that line BufferGeometries cannot be converted to Geometries and consequently cannot be made into dashed lines?

    they can be, manually. something like

    var g = new THREE.Geometry;
    var a = bg.getAttribute ('position').array;
    for (var i = 0; i < a.length; i+=3) {
       g.vertices.push (new THREE.Vector3 (a[i], a[i+1], a[i+2];

    there were some helper methods to set Vector3 from buffer attribute in 3js, but I forget where they are

Comments are closed.