How to paint a polygon by brush?

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 this6815072--791441--upload_2021-2-8_21-31-15.png
and convert it to a list of vertexes just like the little white rect points on the image below. (or piant vertexes immediately)
6815072--791438--upload_2021-2-8_21-29-57.png

I had found a question ( How to make field painter like cities skylines districts? ) asking how to make field painter like cities skylines districts.

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.

:eyes:I don’t know how to make my idea come true.

Someone know how to do this? thanks in advance.

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.

Thank you for your help.:smile: I will try this method and see if it can be used on my project.

:)I implemented this function with Boolean operation, and wrote down my method on this page:在Unity中实现,使用笔刷绘制多边形_unity marchingcubes-CSDN博客

1 Like