Can't find correctly vertices of my object

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):

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 :

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

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)…

what gives me something like that :

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

Have a nice week !
Thanks a lot :slight_smile: !

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:

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.

Thanks a lot !
This tut (Terrain Generation with Perlin Noise · Stephan Baker) + I added a smoothing effect
I tried it like this :slight_smile: (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.

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?