Geometry to BufferGeometry - manipulate vertices

Hey, im still struggling to migrate from Geometry to BufferGeometry (r125), although i mostly used BufferGeometry already. I feel like the documentation for migrating this “breaking change” is missing more complex use cases.
Im currently messing around with positioning single vertex points and making custom shapes from points with applying textures.

For example, Im using BoxGeometry and change position of vertices of the cuboid.
Before r125, when changing a vertex, all faces connected to that vertex would be changed accordingly (indexed geometry):

this.geometry = new THREE.BoxGeometry(1, 1, 1)
this.geometry.vertices[5].x = IIP.x
this.geometry.vertices[5].y = IIP.y
this.geometry.vertices[5].z = IIP.z

this.geometry.verticesNeedUpdate = true

Now Im trying:

this.geometry = new THREE.BoxGeometry(1, 1, 1)
let position = this.geometry.attributes.position

position.setXYZ(5, IIP.x, IIP.y, IIP.z)

position.needsUpdate = true

Unfortunately BufferGeometry has no indexed geometry as I found out. Internet forums are suggesting using BufferGeometryUtils.mergeVertices(geometry) to get a indexed geometry, but it does not have any effect on my geo…?
See this demo

Any help appreciated!

Hi ! You have to remove the normal and uv attributes for BufferGeometryUtils.mergeVertices() to work.
See this fiddle.


Hey, thanks alot! This seems to work. Could you explain why I have to delete normals and uvs? Is it because they need to get recalculated anyway and are false after manipulating the geometry?
Also you’re using BoxBufferGeometry which does not exist in the docs anymore. Is BoxBufferGeometry the same as BoxGeometry in r129?

I think it’s because mergeVertices checks if vertices are identical across all attributes, so if two vertices have the same position but not the same normal, they are not identical, therefore they will not be merged.

Yes that’s the same sorry, I used the BoxBufferGeometry alias out of habit.

1 Like