This is a method that takes about 20 lines but it’s very simple…
STEP 1
Get the array of mesh.triangles
STEP 2
Run through the entire list in a loop, and return 3 sets of edges, made of 2 vertices, for each triangle and put them in a new array of called mesh.edges
, preferably, keep it orderly so that the point with the smallest X, Y, Z is the 1st points of the pair in the list for each edge, that means you have to compare XY and Z for each edge prior to storing it in the array.
The array of mesh.edges
is going to be the same style the mesh.triangles
, except it references the points in the mesh.vertex
array in pairs.
If you’re not worried about having duplicate edges, they need to compare them and order them, just convert the mesh triangles into a new array of edges with 6 vertices per triangle.
By this time you have about 15 lines. mostly the compare XYZ logic in the loop. The rest is 5 lines.
STEP 3
After that you can delete duplicates because they are ordered so that the 1st point is always the lowest XYZ, so you can easily compare the 1st and 2nd points to all the other ones in the array. there should be a lot of duplicates because triangles share edges.
It’s a good learning project I have done stuff seminar. use Debug.DrawLine()
if you want, draw the edges using one of the points and the Vector3
the 2nd one.
Remember that some models don’t share vertices among triangles and 3 times more vertices in the array, duplicates. It doesn’t really matter but it’s good to know, please vote at my answer if it’s useful my feedback is very low, my last profile was the thousand! I can’t give people, karma.
he answer is waiting approval by a moderator. OMG
– ProficientI love this answer! Seems so simple now you have described the theory, the edges of a mesh are ones which are not shared by other tris... Simple but effective. Thank you so much for this answer, this will help me out greatly... Now to work out how to repeat a texture along a line...
– Marchesathank you!
– Eruct