Getting Vertices' positions and changing their position

Hi everyone,

I have just started learning Three.js trying to make small projects to get better.

So my question is , I’m trying to bend plane objects , I managed to find a few examples , Since I dont know how to write shaders as a new learner, I decided to use geometry.vertices.map( at => at.z , at.y, at,x) , but In new versions we cant use this way , I managed to find a few hints but none of them worked, I read the official documentation and some other resources still trying to figure out , Guys Can you guide me how to get vertices positions and manipulate them ?

From the Collection of examples from discourse.threejs.org

BeginnerExample

2021 discourse.threejs.hofk.de

2021-03-25 08.49.52

2021-03-25 08.49.44


related Updating Three.Geo to Three.BufferGeo - #8 by seanwasere

3 Likes

Some minimal code example:

const positionAttribute = geometry.getAttribute( 'position' );

const vertex = new THREE.Vector3();

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

	vertex.fromBufferAttribute( positionAttribute, i ); // read vertex
	
	// do something with vertex

	positionAttribute.setXYZ( i, vertex.x, vertex.y, vertex.z ); // write coordinates back

}
1 Like

Thank you so much, that worked :ok_hand: