# Can't find correctly vertices of my object

**URL:** https://discourse.threejs.org/t/cant-find-correctly-vertices-of-my-object/23947
**Category:** Questions
**Tags:** geometry, buffergeometry, vertices
**Created:** [March 1, 2021, 1:05pm UTC](https://discourse.threejs.org/t/cant-find-correctly-vertices-of-my-object/23947 "2021-03-01T13:05:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![RobertBeric42](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/robertberic42/32/10608_2.png) [@RobertBeric42](https://discourse.threejs.org/u/RobertBeric42)
#### Post date: [March 1, 2021, 1:05pm UTC](https://discourse.threejs.org/t/cant-find-correctly-vertices-of-my-object/23947/1 "2021-03-01T13:05:33Z")

</div>

Hi everybody,

Il previously were used to find my vertices here :  
 → myobject.geometry.vertices

In this example :

let terrainMaterial2 = new THREE.MeshPhysicalMaterial({roughness: 0.5, color: 0xe0d08d});  
terrain2 = new THREE.Mesh(geometry2, terrainMaterial2);  
console.log(“terrain2 geometry vertices”+JSON.stringify(terrain2.geometry.vertices))  
scene.add(terrain2);

I get as a result an array of objects ( **that is what I need** ):

 ![Capture d’écran 2021-03-01 à 13.56.33](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/3/d/3d6cea76f16291a0acaf7fe21bc0bab3de5f98eb.png)

But i recently tried to move my project to react (without react three fiber this time, and downloaded the last version of Three).

What I get now is an ‘undefined’ value for the vertices array.  
So I went to previous posts on the forum to dig a bit and found this issue :

> [@\[SOLVED\] Geometry.vertices is undefined](https://discourse.threejs.org/t/solved-geometry-vertices-is-undefined/3133):
>
> Hello, I’m trying to get the world position of the vertices in my model using geometry.vertices. but it returns undefined for me. I found this issue on SO [https://stackoverflow.com/questions/11495089/how-to-get-the-absolute-position-of-a-vertex-in-three-js](https://stackoverflow.com/questions/11495089/how-to-get-the-absolute-position-of-a-vertex-in-three-js) talking about it, but even using the method as described by WestLangley it will still return undefined. I load my obj using the THREE.OBJLoader, and it loads correctly. I try to get the vertice position using the following code: object.tr…

So i went into my geometry.positions.array and what I found was a mess :

 ![Capture d’écran 2021-03-01 à 14.01.08](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/9/1/9152f5bd155bb26fb88cc18aa43791d31d117e8b.png)

Where I can find my positions but 1) not as array of objects with x: y: z: 2) all in the same array…

So I tried to use this way (and that’s what I’m here, I’m not sure at all it’s logical to do something like this in this situation)…

 ![Capture d’écran 2021-03-01 à 14.02.21](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/f/b/fb5df0f9bd20a777bd13769e30044de122411f07.png)

what gives me something like that :

 ![Capture d’écran 2021-03-01 à 14.04.10](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/7/f/7fe6f7a1b2604403a48f669640d1227084425598.png)

Which definitely seems not to be what i’m searching for…  
What’s do I miss here ?

Have a nice week !  
Thanks a lot 🙂 !

---

<div class="post-metadata">

### Author: ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)
#### Post date: [March 1, 2021, 2:52pm UTC](https://discourse.threejs.org/t/cant-find-correctly-vertices-of-my-object/23947/2 "2021-03-01T14:52:14Z")

</div>

Storing vertex data as array of objects (instances `Vector2`, `Vector3` or `Vector4`) is extremely inefficient and one reason why `THREE.Geometry` was deprecated and removed from the core.

With `THREE.BufferGeometry`, vertex data are organized as typed arrays which hold the data without objects in a consecutive pattern. Meaning [x,y,z, x,y,z, x,y,z, …].

Sometime it is necessary to represents these data as objects for further computation and processing. In this case, use the following pattern:

```javascript
const positionAttribute = mesh.geometry.getAttribute( 'position' );

const vertex = new THREE.Vector3();

for ( let vertexIndex = 0; vertexIndex < positionAttribute.count; vertexIndex ++ ) {

	vertex.fromBufferAttribute( positionAttribute, vertexIndex );

	// do something with vertex

}

```

Notice that a single instance of `Vector3` is reused in order to process vertices for performance reasons.

---

<div class="post-metadata">

### Author: ![RobertBeric42](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/robertberic42/32/10608_2.png) [@RobertBeric42](https://discourse.threejs.org/u/RobertBeric42)
#### Post date: [March 2, 2021, 12:23pm UTC](https://discourse.threejs.org/t/cant-find-correctly-vertices-of-my-object/23947/3 "2021-03-02T12:23:33Z")

</div>

Thanks a lot !  
This tut ([Terrain Generation with Perlin Noise · Stephan Baker](http://www.stephanbaker.com/post/perlinterrain/)) + I added a smoothing effect  
I tried it like this 🙂 (unelegant I think but does what I want)

→ is this the right (or at least one of the rights) way :

```
function randomIntervalNumber (interval, quantity) {
   let array = []
   for (let i = 0; i <= quantity; i ++) {       
    let number = interval*(0.5*i) / quantity
    array.push(number)
   }
   return array.reverse()
}
//console.log(randomIntervalNumber(2, 107))

function adjustVertices(terrain, offset, panela, panelb, modificator) {
    // WITH PERLIN
    var vertices = terrain.geometry.attributes.position.array;
    let scaler = randomIntervalNumber(1, Number(vertices.length))
    for (var i = 0; i <= vertices.length; i += 3) {
        vertices[i+2] = (peak*scaler[i]) * perlin.noise(
            ((terrain.position.x)*offset + vertices[i])/smoothing, 
            ((terrain.position.z) + vertices[i+1])/smoothing
        );
    }
    terrain.geometry.attributes.position.needsUpdate = true;
    terrain.geometry.computeVertexNormals();
}

```

Is this less consuming than the “geometry.vertices” way (because it was the main consumer of all my scene) ?

Thanks a lot those vertex/vertices things are quite uneasy at the beginning.

---

<div class="post-metadata">

### Author: ![JYuan94](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jyuan94/32/36075_2.png) [@JYuan94](https://discourse.threejs.org/u/JYuan94)
#### Post date: [May 6, 2023, 3:09am UTC](https://discourse.threejs.org/t/cant-find-correctly-vertices-of-my-object/23947/4 "2023-05-06T03:09:07Z")

</div>

Hello, friend! Can you help me see how I can solve this problem:

How do I get a vertex somewhere on the three.geometry surface?

> [@How do I get the vertex position somewhere on the PlaneGeometry surface？](https://discourse.threejs.org/t/how-do-i-get-the-vertex-position-somewhere-on-the-planegeometry-surface/51218):
>
> I want the little red spheres, as shown here, to be on the geographic plate, not nested inside I found this method on the Internet, but I was confused that I was using： The index above it has 393,216 points How do I get x and y to find the specified index to get the vertex position? This is my code, I hope you help me to look at, thank you!
