Fill with texture area define by its contour

Hello,

I’m trying to fill the area of non convex objects. I have the points that define their contours but I don’t know how to fill their area. Currently, I have a mesh collider and a line render. The line renderer is used just to drawn the contour using the points. The mesh uses the same set of points to create a collider contour to detect collisions.
The objects have similar shapes to the examples below:

This is how I’m creating the mesh:

objRenderer.positionCount = conePoints.Length;
objRenderer.SetPositions(conePoints);
objRenderer.BakeMesh(mesh, true);
Vector2[] points = new Vector2[mesh.uv.Length];
for (int i = 0; i < mesh.vertices.Length; i++)
{
         points[i] = new Vector2(mesh.vertices[i].x, mesh.vertices[i].z);
}
mesh.uv = points;
objMeshCollider.sharedMesh = mesh;
objMeshCollider.enabled = true;
objMeshFilter.mesh = mesh;

I’ve tried using MeshRenderer but it does not fill the area of the object. It fills the area of the Mesh which is the contour.

Any help would be much appreciated :slight_smile:

I have an example of this in my MakeGeo package: it basically uses the outline to produce infill geometry.

MakeGeo is presently hosted at these locations:

https://bitbucket.org/kurtdekker/makegeo

https://github.com/kurtdekker/makegeo

Look for the testfingerpolygons.unity scene.

1 Like

Thank you for suggestion. The problem is that it’s not working well with non-convex shapes.
6463636--724957--Captura de Tela 2020-10-27 às 15.05.57.png

Yeah, it definitely only handles convex.

Fortunately all polygons can be partitioned into a collection of convex polygons.

Here’s some guidance:

https://en.wikipedia.org/wiki/Polygon_partition

1 Like

Thank you very much! Your suggestion led me to this:
https://wiki.unity3d.com/index.php/Triangulator
It works perfectly!
6463714--724969--Captura de Tela 2020-10-27 às 15.34.55.png

1 Like