コード例 #1
0
    private void Triangulate()
    {
        // For now, just indicate convex and reflex vertices

        if (_convex == null || _reflex == null || _earIndices == null)
        {
            _convex     = new Triangulator.VertexList(_poly.Count);
            _reflex     = new Triangulator.VertexList(_poly.Count);
            _earIndices = new Triangulator.VertexList(_poly.Count);
        }
        else
        {
            _convex.Clear(_poly.Count);
            _reflex.Clear(_poly.Count);
            _earIndices.Clear(_poly.Count);
        }

        _polyVerts = new List <Triangulator.PolyVertex>(_poly.Count);

        var polygonNormal = new Vector3(0f, 0f, -1f);

        Triangulator.SortVerticesByAngleType(_poly, polygonNormal, _convex, _reflex);
        Triangulator.SetupPolyVerts(_poly, _polyVerts, polygonNormal);
        var earCount = Triangulator.TryFindEarindices(_poly, _polyVerts, _earIndices);

        //Debug.LogFormat("Ear count: {0}", earCount);

        _tris = Triangulator.TriangulatePolygon(_poly, polygonNormal);
    }