Change the position of 1 specific vertex in an object

Suppose I have 1 cube, I need to access the vertex Buffer and change the position of 1 specific vertex (for example, move 5 in the Y axis to any of the vertexes of one of the corners of the cube, but only 1). What would be the code for me to be able to indicate one of the corners to move?

I have managed to move them all, following the examples in the forum, but I can’t move just 1,

thanks for your help

Have a look at this example - it gets all vertices (from the vertex buffer of the mesh), and modifies them all every frame. You need to modify just one. And then set all back on the mesh.

https://playcanvas.github.io/#/graphics/mesh-deformation

Thanks for answering, that is exactly what I can do, modify all of them, what I cannot do is modify only 1. I would greatly appreciate a piece of code that guides me on how to select a certain vertex within the buffer.

All code would be the same, but instead of looping over all vertices and changing their values, you’d just change a single value. For example if you want to change vertex 1, you’d update its x, y, and z like this:

var vertexIndex = 1;
positions[vertexIndex * 3 + 0] = x;
positions[vertexIndex * 3 + 1] = y;
positions[vertexIndex * 3 + 2] = z;
1 Like

Thanks, I’m going to try this, I come from the world of 3D, and there are still things that I don’t fully understand. Thanks again