示例#1
0
    /// <summary>
    /// Triangulate this JelloClosedShape.
    /// Make sure there are no duplicate points in JelloClosedShape.EdgeVertices or JelloClosedShape.InternalVertices or else the triangulator will fail.
    /// </summary>
    public void Triangulate()
    {
        JelloPoly2Tri.JelloPolygonPoint[] points = new JelloPoly2Tri.JelloPolygonPoint[mEdgeVertices.Length];

        for (int i = 0; i < mEdgeVertices.Length; i++)
        {
            points[i] = new JelloPoly2Tri.JelloPolygonPoint((double)mEdgeVertices[i].x, (double)mEdgeVertices[i].y);
            points[i].polygonIndex = i;
        }

        JelloPoly2Tri.Polygon poly = new JelloPoly2Tri.Polygon(points);

        points = new JelloPoly2Tri.JelloPolygonPoint[mInternalVertices.Length];
        for (int i = 0; i < mInternalVertices.Length; i++)
        {
            points[i] = new JelloPoly2Tri.JelloPolygonPoint((double)InternalVertices[i].x, (double)InternalVertices[i].y);
            points[i].polygonIndex = i + mEdgeVertices.Length;
            poly.AddSteinerPoint(points[i]);
        }

        JelloPoly2Tri.P2T.Triangulate(poly);

        if (mTriangles == null || mTriangles.Length != poly.Triangles.Count * 3)
        {
            mTriangles = new int[poly.Triangles.Count * 3];
        }

        JelloPoly2Tri.JelloPolygonPoint jpp;
        for (int i = 0; i < poly.Triangles.Count; i++)        //reverse triangle winding as well //TODO make sure this works for CCW and CW polygons...
        {
            jpp = (JelloPoly2Tri.JelloPolygonPoint)poly.Triangles[i].Points[2];
            mTriangles[3 * i + 0] = jpp.polygonIndex;
            jpp = (JelloPoly2Tri.JelloPolygonPoint)poly.Triangles[i].Points[1];
            mTriangles[3 * i + 1] = jpp.polygonIndex;
            jpp = (JelloPoly2Tri.JelloPolygonPoint)poly.Triangles[i].Points[0];
            mTriangles[3 * i + 2] = jpp.polygonIndex;
        }
    }
示例#2
0
    //triangulate
    /// <summary>
    /// Triangulate this shape.
    /// Make sure there are no duplicate points in JelloClosedShape.EdgeVertices or JelloClosedShape.InternalVertices or else the triangulator will fail.
    /// </summary>
    public static int[] Triangulate(Vector2[] shape)
    {
        JelloPoly2Tri.JelloPolygonPoint[] points = new JelloPoly2Tri.JelloPolygonPoint[shape.Length];

        for (int i = 0; i < shape.Length; i++)
        {
            points[i] = new JelloPoly2Tri.JelloPolygonPoint((double)shape[i].x, (double)shape[i].y);
            points[i].polygonIndex = i;
        }

        JelloPoly2Tri.Polygon poly = new JelloPoly2Tri.Polygon(points);

//		points = new JelloPoly2Tri.JelloPolygonPoint[mInternalVertices.Length];
//		for(int i = 0; i < mInternalVertices.Length; i++)
//		{
//			points[i] = new JelloPoly2Tri.JelloPolygonPoint((double)InternalVertices[i].x, (double)InternalVertices[i].y);
//			points[i].polygonIndex = i + shape.Length;
//			poly.AddSteinerPoint(points[i]);
//		}

        JelloPoly2Tri.P2T.Triangulate(poly);

        int[] triangles = new int[poly.Triangles.Count * 3];

        JelloPoly2Tri.JelloPolygonPoint jpp;
        for (int i = 0; i < poly.Triangles.Count; i++)        //reverse triangle winding as well //TODO make sure this works for CCW and CW polygons...
        {
            jpp = (JelloPoly2Tri.JelloPolygonPoint)poly.Triangles[i].Points[2];
            triangles[3 * i + 0] = jpp.polygonIndex;
            jpp = (JelloPoly2Tri.JelloPolygonPoint)poly.Triangles[i].Points[1];
            triangles[3 * i + 1] = jpp.polygonIndex;
            jpp = (JelloPoly2Tri.JelloPolygonPoint)poly.Triangles[i].Points[0];
            triangles[3 * i + 2] = jpp.polygonIndex;
        }

        return(triangles);
    }
    /// <summary>
    /// Triangulate this JelloClosedShape.
    /// Make sure there are no duplicate points in JelloClosedShape.EdgeVertices or JelloClosedShape.InternalVertices or else the triangulator will fail.
    /// </summary>
    public void Triangulate()
    {
        JelloPoly2Tri.JelloPolygonPoint[] points = new JelloPoly2Tri.JelloPolygonPoint[mEdgeVertices.Length];

        for(int i = 0; i < mEdgeVertices.Length; i++)
        {
            points[i] = new JelloPoly2Tri.JelloPolygonPoint((double)mEdgeVertices[i].x, (double)mEdgeVertices[i].y);
            points[i].polygonIndex = i;
        }

        JelloPoly2Tri.Polygon poly = new JelloPoly2Tri.Polygon(points);

        points = new JelloPoly2Tri.JelloPolygonPoint[mInternalVertices.Length];
        for(int i = 0; i < mInternalVertices.Length; i++)
        {
            points[i] = new JelloPoly2Tri.JelloPolygonPoint((double)InternalVertices[i].x, (double)InternalVertices[i].y);
            points[i].polygonIndex = i + mEdgeVertices.Length;
            poly.AddSteinerPoint(points[i]);
        }

        JelloPoly2Tri.P2T.Triangulate(poly);

        if(mTriangles == null || mTriangles.Length != poly.Triangles.Count * 3)
            mTriangles = new int[poly.Triangles.Count * 3];

        JelloPoly2Tri.JelloPolygonPoint jpp;
        for(int i = 0; i < poly.Triangles.Count; i++) //reverse triangle winding as well //TODO make sure this works for CCW and CW polygons...
        {
            jpp = (JelloPoly2Tri.JelloPolygonPoint)poly.Triangles[i].Points[2];
            mTriangles[3 * i + 0] = jpp.polygonIndex;
            jpp = (JelloPoly2Tri.JelloPolygonPoint)poly.Triangles[i].Points[1];
            mTriangles[3 * i + 1] = jpp.polygonIndex;
            jpp = (JelloPoly2Tri.JelloPolygonPoint)poly.Triangles[i].Points[0];
            mTriangles[3 * i + 2] =  jpp.polygonIndex;
        }
    }
    //triangulate
    /// <summary>
    /// Triangulate this shape.
    /// Make sure there are no duplicate points in JelloClosedShape.EdgeVertices or JelloClosedShape.InternalVertices or else the triangulator will fail.
    /// </summary>
    public static int[] Triangulate(Vector2[] shape)
    {
        JelloPoly2Tri.JelloPolygonPoint[] points = new JelloPoly2Tri.JelloPolygonPoint[shape.Length];

        for(int i = 0; i < shape.Length; i++)
        {
            points[i] = new JelloPoly2Tri.JelloPolygonPoint((double)shape[i].x, (double)shape[i].y);
            points[i].polygonIndex = i;
        }

        JelloPoly2Tri.Polygon poly = new JelloPoly2Tri.Polygon(points);

        //		points = new JelloPoly2Tri.JelloPolygonPoint[mInternalVertices.Length];
        //		for(int i = 0; i < mInternalVertices.Length; i++)
        //		{
        //			points[i] = new JelloPoly2Tri.JelloPolygonPoint((double)InternalVertices[i].x, (double)InternalVertices[i].y);
        //			points[i].polygonIndex = i + shape.Length;
        //			poly.AddSteinerPoint(points[i]);
        //		}

        JelloPoly2Tri.P2T.Triangulate(poly);

        int[] triangles = new int[poly.Triangles.Count * 3];

        JelloPoly2Tri.JelloPolygonPoint jpp;
        for(int i = 0; i < poly.Triangles.Count; i++) //reverse triangle winding as well //TODO make sure this works for CCW and CW polygons...
        {
            jpp = (JelloPoly2Tri.JelloPolygonPoint)poly.Triangles[i].Points[2];
            triangles[3 * i + 0] = jpp.polygonIndex;
            jpp = (JelloPoly2Tri.JelloPolygonPoint)poly.Triangles[i].Points[1];
            triangles[3 * i + 1] = jpp.polygonIndex;
            jpp = (JelloPoly2Tri.JelloPolygonPoint)poly.Triangles[i].Points[0];
            triangles[3 * i + 2] =  jpp.polygonIndex;
        }

        return triangles;
    }