Hey guys:smile:
Now I want to get a polygon defined by a sorted list of vertex coordinates. For example 4 coordinate ,(0,0) (1,0) (1,1) (0,1), define a rectangle.
And I hope I can use a brush to paint this polygon.
Maybe I can paint a texture like this
and convert it to a list of vertexes just like the little white rect points on the image below. (or piant vertexes immediately)
There is a answer mentioned about Marching Squares algorithm. After having a quick look on the algorithm, I think it will work great when I just need to visualize the edge of the region.
But now I wanna get a set of vertices sorted counterclockwise. I don’t think the algorithm will work in this case.
This problem is a combination of computer vision and constructive geometry.
If you start from a computer vision package such as OpenCV (there is a Unity3D package available on the asset store), that can give you a real leg up on a set of vectors defining the boundary of your area.
From that you could perhaps construct a set of continuous lines forming a polygon.
It’s even possible that OpenCV has some kind of polygon-creation helper routines in it nowadays… I haven’t used OpenCV since 2014, but I imagine it has had updates.