# Change vertex position with BufferGeometry

**URL:** <https://discourse.threejs.org/t/change-vertex-position-with-buffergeometry/27072>\
**Category:** Questions\
**Tags:** buffergeometry, geometry\
**Created:** [June 9, 2021, 3:14pm UTC](https://discourse.threejs.org/t/change-vertex-position-with-buffergeometry/27072 "2021-06-09T15:14:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fluqz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fluqz/32/6279_2.png) [@Fluqz](https://discourse.threejs.org/u/Fluqz)\
**Post date:** [June 9, 2021, 3:14pm UTC](https://discourse.threejs.org/t/change-vertex-position-with-buffergeometry/27072/1 "2021-06-09T15:14:16Z")

</div>

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.

```javascript
        // 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!

---

<div class="post-metadata">

**Author:** ![hofk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/hofk/32/44944_2.png) [@hofk](https://discourse.threejs.org/u/hofk)\
**Post date:** [June 9, 2021, 3:27pm UTC](https://discourse.threejs.org/t/change-vertex-position-with-buffergeometry/27072/2 "2021-06-09T15:27:45Z")

</div>

Here I use position.setXYZ( ). Maybe it helps?  
From the [Collection of examples from discourse.threejs.org](https://discourse.threejs.org/t/collection-of-examples-from-discourse-threejs-org/4315)  
[SpiralFromCylinder](https://hofk.de/main/discourse.threejs/2021/SpiralFromCylinder/SpiralFromCylinder.html)

---

<div class="post-metadata">

**Author:** ![rrrr\_rrrr](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rrrr_rrrr/32/7697_2.png) [@rrrr\_rrrr](https://discourse.threejs.org/u/rrrr_rrrr)\
**Post date:** [June 9, 2021, 3:52pm UTC](https://discourse.threejs.org/t/change-vertex-position-with-buffergeometry/27072/3 "2021-06-09T15:52:04Z")

</div>

BufferGeometry.attributes.position.needsUpdate = !0;

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [June 10, 2021, 7:09am UTC](https://discourse.threejs.org/t/change-vertex-position-with-buffergeometry/27072/4 "2021-06-10T07:09:06Z")

</div>

> [@Fluqz](#):
>
> `let position = `

and then

> [@Fluqz](#):
>
> `positions.setXYZ`

The last “s” in “position **s** ” is not needed.

---

<div class="post-metadata">

**Author:** ![Fluqz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fluqz/32/6279_2.png) [@Fluqz](https://discourse.threejs.org/u/Fluqz)\
**Post date:** [June 10, 2021, 9:41am UTC](https://discourse.threejs.org/t/change-vertex-position-with-buffergeometry/27072/5 "2021-06-10T09:41:23Z")

</div>

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 changing 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
