How get faces( triangle ) data from buffergeometry

Buffer geometries can be indexed or non-indexed. In the first case, you get the triangle indices (a,b,c) like so:

const index = geometry.getIndex();

for ( let i = 0; i < index.count; i += 3 ) {

    const a = index.getX( i );
    const b = index.getX( i + 1 );
    const c = index.getX( i + 2 );

}

If the geometry is non-indexed, use the position attribute which holds the actual vertices.

const position = geometry.getAttribute( 'position' );

for ( let i = 0; i < position.count; i += 3 ) {

    const a = i;
    const b = i + 1;
    const c = i + 2;

}

The face indices can now be used to retrieve the actual vertex data from the buffer attributes.

8 Likes