Change vertex position with BufferGeometry

Hey Guys, im trying to migrate from Geometry to BufferGeometry. I have a few cases where I was using BoxGeometry as initial Geometry and manipulated each vertex to fit my needs.

        //   Y
        //   |
        //   |
        //   | 
        //   |4 +--------+ 1
        //   | /|       /|
        //   |/ |      / |
        // 5 +--|-----+ 0|
        //   |  |     |  |
        //   | 6+_____|__+3
        //   | /      | /
        //   |/       |/
        // 7 +--------+ 2-------- X

With the old Geometry I would do something like this

            this.geometry = new THREE.BoxGeometry(1, 1, 1)

            this.geometry.vertices[5].x = IIP.x
            this.geometry.vertices[5].y = 2
            this.geometry.vertices[5].z = IIP.z

            this.geometry.vertices[7].x = IIP.x
            this.geometry.vertices[7].y = 0
            this.geometry.vertices[7].z = IIP.z

            this.geometry.verticesNeedUpdate = true
            this.mesh.updateMatrixWorld()

Now with BufferGeometry I tried to do it like so

            this.geometry = new THREE.BoxGeometry(1, 1, 1)
            let position = this.geometry.attributes.position
            position.setXYZ(5, IIP.x, 2, IIP.z)

            position.setXYZ(7, IIP.x, 0, IIP.z)

            position.needsUpdate = true
            this.mesh.updateMatrixWorld()

and its not working unfortunately. I guess im not using the right index?
Any help appreaciated!

Here I use position.setXYZ( ). Maybe it helps?
From the Collection of examples from discourse.threejs.org
SpiralFromCylinder

1 Like

BufferGeometry.attributes.position.needsUpdate = !0;

and then

The last “s” in “positions” is not needed.

Hey, that was just a typo from copy pasting it to here sorry!

I made a jsFiddle where I actually got it to work, well partly, because I noticed that if i change one vertex, only one face is chaning accordingly. I found the BufferGeometryUtils.mergeVertices() function, but that did not work.

I guess the error here has to be somewhere else. Gonna update this as soon as I have time to work on it again.
Thanks already