Procedurally generate 3D mesh from 2D image

I’ve run into a bit of a wall here. I want to procedurally generate a 3D mesh from a sprite, and so far, I’ve gotten about halfway through. I want a mesh that retains the outline of the original sprite (but scaled up slightly) on both sides and simply extrudes it along the third axis to generate the mesh. I’ve managed to create the single, scaled up face, and extrude the points along the final axis, but now I’ve hit a road block. I want to generate faces along the edge to create the volume, but the vertices are unsorted. Currently, I am generating faces by index, but that won’t work because Unity doesn’t know how to sort a sprite’s vertices by position, and neither do I. How do I get around this? Do I have to generate the edge faces by position and not by index? Or is there a way I can sort the vertices by index without messing up the triangles (or modify the triangles to accommodate in the process)? The screenshots accessible at the link below elaborate the effect I am trying to achieve, and the actual behavior of the generation.

.

https://drive.google.com/open?id=1atWReVuvLxDMS9cn2c-Q39gAdsZKDvEJ

.

Image descriptions:

.

  • Original sprite (with vertices and triangles shown from debug view)

.

  • Procedurally generated mesh

.

  • Expected edge extending backwards from face.

.

  • Actual behavior along the rest of the mesh

.

  • Closer look at one side

there is an order to it, you are just looping through it wrong, it would also help to have intermediate vertices every so often based on the image resolution
its late, but I hope you found your answer some time ago.