I'm having trouble with removing duplicate vertices from a SphereGeomerty
. I want to get rid of the seam on side of the geometry, because it don't align well if I update the vertex positions.
Problem is that I can't create a new geometry with a filtered vertex position list, I get an
[.Offscreen-For-WebGL-000001B883B499D0]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 0
error.
More strange, if I put back the original vertex list to the bufferGeometry nothing is rendered, but the error is gone:
let positions = sphere.attributes.position.array;
filteredGeometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
I'm filtering vertices like this:
function removeDuplicateVertices(vertices) {
var positionLookup = [];
var final = [];
for( let i = 0; i < vertices.length-3; i += 3 ) {
var index = vertices[i] + vertices[i + 1] + vertices[i + 2];
if( positionLookup.indexOf( index ) == -1 ) {
positionLookup.push( index );
final.push(vertices[i])
final.push(vertices[i+1])
final.push(vertices[i+2])
}
}
return final;
}