Its probably obvious, but I can’t seem to get the logic to get the correct triangle shapes/placements and basically draw a wire mesh overlay.
I’m going through a list of triangles in my code, and drawing a blue line for each of the edges.
Gizmos.color = Color.blue;
var v = meshFilter.mesh.vertices;
var draw = new System.Action<Vector3, Vector3>((a, b) =>
{
Gizmos.DrawLine(
transform.TransformPoint(a),
transform.TransformPoint(b));
});
foreach (int t in meshFilter.mesh.triangles)
{
if (t + 3 > v.Length) break;
draw(v[t], v[t + 1]);
draw(v[t], v[t + 2]);
draw(v[t+2], v[t + 1]);
}
The first weird part is that in my model, the highest index returned from mesh.Triangles is 325, but the highest vertex index is 326. My understanding is that triangle returns the first index of 3 vertices, meaning I expected vertices 325, 326 & 327. 327 is out of bounds of the vertex array.
The second weird part is the drawn lines for the remaining parts:
While the triangles in general are correctly placed, there are clearly extra lines being drawn where there are no faces. I checked in Blender, and there are no edges not connected to a face.
It seems I’m grabbing the wrong vertices for the triangles, but I’m not sure why. Any ideas?