BufferGeometryUtils.mergeVertices - seems not to merge all identical vertices in three.js
Solution 1:
The merge process is functioning as expected. If you look at the count of each attribute of the original geometry
you'll get 36, but if you look at the count of each attribute of the merged indexedGeo
, you'll get 24:
console.log(geometry.getAttribute("position").count); // 36
console.log(indexedGeo.getAttribute("position").count); // 24
The problem you're encountering is that the merge method looks at all attributes before merging. In your case, position, normal, uv
. The corners of a box have 3 vertices, each with its own normal pointing in 3 directions (one pointing up, one right, and one forward, for example). Since each vertex contains unique normal
data on how to render its respective face, these vertices cannot be merged. Even though their position is the same, the other attributes are different.