I want to create an editor script that allows me to create a mesh. This isn’t a complicated 3d mesh creation I’m looking for, I want to use them on a 2d game, to serve as visual representation of platforms and walls etc.
Right now I can make an editor script that allows me to create a polygon collider 2d by clicking and defining points. This is quite easy because polygoncollider2d has useful functions to create colliders. But I need an actual mesh, a set of polygons, to create a visual representation of this collider.
I read about the mesh component and figured how to create meshes. But I’m completely stumped in creating an algorithm that generates concave polygons by simply defining a set of ordered points, similarly to the way PolygonCollider2D.SetPath() works.
I didn’t get much help from theforums, so I decided to try here
Triangulator! I knew there had to be a keyword I was missing from my googling. Thanks a bunch, this is exactly what I need :) I mean, probably, I'm still checking it out, but the first tests are looking promising.
so basically you create mesh, and arrays with vertices, then you group them in array triangles (the array is 3 times longer then the vertices array)
Hello :) As I said in the question, I read about the mesh component and I know how to create a mesh. I need an algorithm that takes a set of ordered points and creates the full mesh. There's a big difference between taking three vertices and making a triangle and taking 23 vertices and X triangles and creating them depending on the order of points. I don't know how to detect consistent shapes that can be made and stuff like that
It might be obsolete, but for any other people with an issue like that: I try the same with an CustomEditor script (just for fun for now) . I thought about using an origin object (or the middle of all point) , to use it for every second point of a triangle. But it would have to be in the center for it, to be consistent and nicely shaped. So if you have a Centerpoint and place new point around it (best viewed by some Handles) and after at least three points, click a butten, to create a mesh, it would take point[0] as the first, the center as the second, and point[1] as the third point, for the first triangle. For the second triangle it would take point[1] as the first, the center as the second and point[2] as the third point. And so on… You get the idea.
Triangulator! I knew there had to be a keyword I was missing from my googling. Thanks a bunch, this is exactly what I need :) I mean, probably, I'm still checking it out, but the first tests are looking promising.
– diegzumillo_1actually this is very helpful for me too, thanks!
– komodorThis looks like what I have been looking for, too. Thank you!
– Ariopolis