Hi, I finally found the solution to my problem.
I found a free physics engine in the asset store, named FarseerUnity.
That asset has a class named "Bayazit Decomposer", which obviously uses Bayazit's algorithm to decompose the polygon.
So I copyed the functions that were necessary and the class is now working perfectly.
Here is the class:
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
///
/// This class is took from the "FarseerUnity" physics engine, which uses Mark Bayazit's decomposition algorithm.
/// I also have to make it work with self-intersecting polygons, so I'll use another different algorithm to decompose a self-intersecting polygon into several simple polygons,
/// and then I would decompose each of them into convex polygons.
///
//From phed rev 36
///
/// Convex decomposition algorithm created by Mark Bayazit (http://mnbayazit.com/)
/// For more information about this algorithm, see http://mnbayazit.com/406/bayazit
///
public static class BayazitDecomposer
{
private static Vector2 At(int i, List vertices)
{
int s = vertices.Count;
return vertices[i Copy(int i, int j, List vertices)
{
List p = new List();
while (j
/// Decompose the polygon into several smaller non-concave polygon.
/// If the polygon is already convex, it will return the original polygon, unless it is over Settings.MaxPolygonVertices.
/// Precondition: Counter Clockwise polygon
///
///
///
public static List
- > ConvexPartition(List
- > list = new List
- >();
float d, lowerDist, upperDist;
Vector2 p;
Vector2 lowerInt = new Vector2();
Vector2 upperInt = new Vector2(); // intersection points
int lowerIndex = 0, upperIndex = 0;
List
- > listOfConvexPolygonPoints = BayazitDecomposer.ConvexPartition (vertices);
foreach (List