# drawing lines procedurally along a meshes triangle perimeters

Hey all, relative unity noob here currently working on a procedural map generator. The art style i’m trying to achieve is similar to old vector graphics games from the 90s, similar to the games discussed on this forum thread:

I want my geometry to be non translucent so im thinking the best way to do this is by creating textures procedurally. I want lines to be drawn from vertex to vertex for every triangle in my mesh, with the exception of the “hypotenuse” so the final result of 2 adjacent triangles will be an outlined square as opposed to 2 adjacent triangles. I’m thinking if i created the texture at the same time that I create the mesh is the most efficient way to do this.

I’ve looked into procedural texture generation and it seems like what is most commonly done to draw on the UV of an entire mesh, as opposed to individual triangles. Anybody know how to draw on individual triangles?

The best way to handle this will be dependent on how you’ve generated your mesh. The simplest thing to do would be to make a texture that consists of a single triangle, and you can set every triangle worth of UVs to the same 3 UV points.

This only works if your mesh generation creates 3 vertices for every triangle and doesn’t share them between triangles. That would be generally not the recommended way to make meshes, but it’s advisable for this scenario.

It’s so advisable for this scenario that, even if your mesh isn’t built that way, I’d suggest altering your mesh after generation so that it is. Here’s a function that will do that (untested, and it definitely generates garbage so don’t run this every frame without optimizing it, but it should work). While it’s at it it sets the UV array to match a single triangle in the texture. (A right triangle “leaning” against the left side of the image, to be specific - adjust as needed if the triangles end up looking lopsided)

``````    Mesh GetTriangulatedMesh(Mesh m) {
int[] triangles = m.triangles;
Vector3[] oldVerts = m.vertices;
Vector3[] newVertices = new Vector3[triangles.Length];
Vector2[] newUV = new Vector2[triangles.Length];
for (int v = 0; v < triangles.Length; v++) {
newVertices [v] = oldVerts [triangles [v]];
if (v % 3 == 0)
newUV [v] = new Vector2 (0, 0);
else if (v % 3 == 1)
newUV [v] = new Vector2 (0, 1);
else
newUV [v] = new Vector2 (1, 0);
triangles [v] = v;
}
m.Clear ();
m.vertices = newVertices;
m.uv = newUV;
m.triangles = triangles;
return m;
}
``````

awesome thanks! I’ll let you know how it goes!