# setVerticesData and getVerticesData

**URL:** <https://forum.babylonjs.com/t/setverticesdata-and-getverticesdata/34031>\
**Category:** Questions\
**Tags:** mesh\
**Created:** [September 19, 2022, 6:16am UTC](https://forum.babylonjs.com/t/setverticesdata-and-getverticesdata/34031 "2022-09-19T06:16:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbwow123](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hbwow123](https://forum.babylonjs.com/u/hbwow123)\
**Post date:** [September 19, 2022, 6:16am UTC](https://forum.babylonjs.com/t/setverticesdata-and-getverticesdata/34031/1 "2022-09-19T06:16:06Z")

</div>

hello,  
i used setVerticesData() to update mesh vertex and then i used getVerticesData() to get mesh vertex positions,but it cause a error like that:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/8/d/8d28f48f5332d13abb1a595aee09f51f218d3b7a.png)  
this is my code:

```auto
 var newNormals: BABYLON.Nullable<BABYLON.FloatArray> = [];
 BABYLON.VertexData.ComputeNormals(positions, indices, newNormals);

 mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions);
 mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, newNormals);
 mesh.setIndices(indices, indices.length);

 let positions2 = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);

 console.log(positions2);

```

i want to know how to fix it…can you help me ? thanks very much!!

---

<div class="post-metadata">

**Author:** ![hbwow123](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hbwow123](https://forum.babylonjs.com/u/hbwow123)\
**Post date:** [September 19, 2022, 9:00am UTC](https://forum.babylonjs.com/t/setverticesdata-and-getverticesdata/34031/2 "2022-09-19T09:00:41Z")

</div>

yeah，i found the reason and solved it ~~~~~~

i used positions to handle data, it should use new array to handle data like this

```auto
let positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
    let indices = mesh.getIndices();
    if (!positions || positions.length === 0 || !indices || indices.length === 0) {
      return null;
    }
    console.log(moveVector);
  
    let vertexPosition: BABYLON.Vector3[] = [];
    for (let i = 0; i < positions.length; i = i + 3) {
        let pos = new BABYLON.Vector3(positions[i], positions[i + 1], positions[i + 2]);
        vertexPosition.push(pos);
    }

    // use new array to handle data
    let pos = [];
    for (let i = 0;i<positions.length;i++){
        pos.push(positions[i]);
    }
    
    let lineIndice = dxmInfoNode.metadata.lineIndice;
    for (let indices of lineIndice){
        let vertexPos1 = vertexPosition[indices[0]];
        let vertexPos2 = vertexPosition[indices[1]];
        for (let i = 0; i < pos.length; i += 3) {
            let v1 = BABYLON.Vector3.FromArray(pos!, i);
            if (v1.x === vertexPos1.x && v1.y === vertexPos1.y && v1.z === vertexPos1.z){
                console.log("："+ i);
                pos[i] = vertexPos1.x + moveVector.x;
                pos[i+1] = vertexPos1.y + moveVector.y;
                pos[i+2] = vertexPos1.z + moveVector.z;
            }else if (v1.x === vertexPos2.x && v1.y === vertexPos2.y && v1.z === vertexPos2.z){
                console.log("："+ i);
                pos[i] = vertexPos2.x + moveVector.x;
                pos[i+1] = vertexPos2.y + moveVector.y;
                pos[i+2] = vertexPos2.z + moveVector.z;
            }   
        }

    }

```

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [September 19, 2022, 2:30pm UTC](https://forum.babylonjs.com/t/setverticesdata-and-getverticesdata/34031/3 "2022-09-19T14:30:56Z")

</div>

Would be cool to share so that it might help others having the same issue ?
