I am looking to expand a system I have. I want to be able to find the vertices that are connected to an edge. How would I do this? At runtime mind you.
I am looking to expand a system I have. I want to be able to find the vertices that are connected to an edge. How would I do this? At runtime mind you.
Well try to access to triangle, triangle will lead you to vertex, each triangle being 3 edges by definition.
The triangles and the vertices are accessible through the Mesh class, see:
Right. However how would I know which edges I want? I basically want to modify the edges near the outskirts of the mesh like in the image I show in the OP.
To modify an edge, you need to modify the vertices defining that edge.
The way Unity stores meshes does not give direct data about edges and their connectivity. Edge are implicit, only triangles and vertices are explicitly stored.
If you want the edge vertices for that specific cube, you need to know how the cube is built. You could build the cube yourself or print out it’s data to the console and study its vertices and triangles arrays to figure out the edges you want.
If you want a more generalized solution, that is to query the vertices of a given edge of a given mesh, you would need to implement your own mesh data structure since the built-in Unity Mesh class does not support such query. You can get some inspiration from how Blender internally represents meshes: see BMesh.
Or half edge topology.
When do you need to alter the edges?
A mesh is basically a graph, you can analyse the structure to infer what you want, in this case it seems you would want to avoid edges that border two co planar triangle. So looping through all triangles and finding shared edges of them, would also you to NOT mark edges in which the coplanarity of their triangle is verified.
Is this only for cubes? On a cube all vertices are connected to an edge. So just grab all vertices.
For more complicated meshes you really need to define what constitutes an edge. Once you have that down, you can work out ways to find the edges.