I want to create a 2D procedural mesh during runtime, and i have given the vertices of the mesh, like shown in the picture on the left.
How do i know which vertices i have to connect to triangles, so the mesh looks correct, like shown on the right?
Alternatively: i there any other way in unity, to create a procedural 2D-shape, with only the vertices known?
That’s an odd question. The vertices are there to define the triangles. If these vertices are just a random set of points though and you want a mesh to just cover the (potentially) concave area then you could use a 3rd party library to do that when you have the exterior points such as a LibTessDotNet.
A hacky way to do it without caring for the details or implementing anything would be to provide the outline (exterior) points to a PolygonCollider2D and use Collider2D.CreateMesh to create a mesh for you.
My phone number contains 2, 4, 5, 7 and 9… that is ALL the digits in my phone number. Call me!
See how there is missing information about which vertices are involved in making triangles?
Once you figure out how to choose your vertices, you’re welcome to look around my MakeGeo project for ideas on how to make interesting procedural geometry in Unity3D:
I think i missed an import Information in my orginal post. I do have the Vertices, and i do know the order of the vertices, to create the outer edge. The only thing i didn’t know, how to choose the correct vertices to create a triangle.
Glad it worked. Know that you’ll have to wait until 2023.1 but that version introduces a Delaunay option to Collider2D.CreateMesh which will produce a much cleaner mesh in most cases.