I'm struggling with removing duplicate vertices from a SphereGeomerty
. I need to eliminate the seam on one side of the geometry as it doesn't align properly when updating the vertex positions.
The issue arises when attempting to create a new geometry with a filtered list of vertex positions, resulting in an error:
[.Offscreen-For-WebGL-000001B883B499D0]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out-of-range vertices in attribute 0
It becomes even more perplexing because if I revert to using the original vertex list for the BufferGeometry, nothing is rendered but the error disappears:
let positions = sphere.attributes.position.array;
filteredGeometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
My method for filtering vertices is as follows:
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;
}