Пример #1
0
    public static Mesh TriangulateAdvanced(Polygon2D polygon, Vector2 UVScale, Vector2 UVOffset)
    {
        polygon.Normalize();
        TriangulationWrapper.Polygon poly = new TriangulationWrapper.Polygon();

        List <Vector2> pointsList   = null;
        List <Vector2> UVpointsList = null;

        Vector3 v = Vector3.zero;

        foreach (Vector2D p in polygon.pointsList)
        {
            v = p.vector;
            poly.outside.Add(v);
            poly.outsideUVs.Add(new Vector2(v.x / UVScale.x + .5f + UVOffset.x, v.y / UVScale.y + .5f + UVOffset.y));
        }

        foreach (Polygon2D hole in polygon.holesList)
        {
            pointsList   = new List <Vector2> ();
            UVpointsList = new List <Vector2> ();
            foreach (Vector2D p in hole.pointsList)
            {
                v = p.vector;
                pointsList.Add(v);
                UVpointsList.Add(new Vector2(v.x / UVScale.x + .5f, v.y / UVScale.y + .5f));
            }
            poly.holes.Add(pointsList);
            poly.holesUVs.Add(UVpointsList);
        }

        return(TriangulationWrapper.CreateMesh(poly));
    }
Пример #2
0
    public static Mesh TriangulateAdvanced(Polygon2D polygon, Vector2 UVScale, Vector2 UVOffset)
    {
        foreach (Pair2D p in Pair2D.GetList(new List <Vector2D>(polygon.pointsList)))
        {
            if (polygon.pointsList.Count < 4)
            {
                break;
            }
            if (Vector2D.Distance(p.A, p.B) < 0.005f)
            {
                Debug.LogWarning("Slicer2D: Polygon points are too close");
                polygon.pointsList.Remove(p.A);
            }
        }

        TriangulationWrapper.Polygon poly = new TriangulationWrapper.Polygon();

        List <Vector2> pointsList   = null;
        List <Vector2> UVpointsList = null;

        Vector3 v = Vector3.zero;

        foreach (Vector2D p in polygon.pointsList)
        {
            v = p.ToVector2();
            poly.outside.Add(v);
            poly.outsideUVs.Add(new Vector2(v.x / UVScale.x + .5f + UVOffset.x, v.y / UVScale.y + .5f + UVOffset.y));
        }

        foreach (Polygon2D hole in polygon.holesList)
        {
            pointsList   = new List <Vector2> ();
            UVpointsList = new List <Vector2> ();

            foreach (Vector2D p in hole.pointsList)
            {
                v = p.ToVector2();
                pointsList.Add(v);
                UVpointsList.Add(new Vector2(v.x / UVScale.x + .5f, v.y / UVScale.y + .5f));
            }

            poly.holes.Add(pointsList);
            poly.holesUVs.Add(UVpointsList);
        }

        return(TriangulationWrapper.CreateMesh(poly));
    }
    public static Mesh PerformTriangulation(Polygon2D polygon, Vector2 UVScale, Vector2 UVOffset)
    {
        Polygon2DList.RemoveClosePoints(polygon.pointsList);

        foreach (Polygon2D hole in polygon.holesList)
        {
            Polygon2DList.RemoveClosePoints(hole.pointsList);
        }

        TriangulationWrapper.Polygon poly = new TriangulationWrapper.Polygon();

        List <Vector2> pointsList   = null;
        List <Vector2> UVpointsList = null;

        Vector3 v = Vector3.zero;

        foreach (Vector2D p in polygon.pointsList)
        {
            v.x = (float)p.x;
            v.y = (float)p.y;

            poly.outside.Add(v);
            poly.outsideUVs.Add(new Vector2(v.x / UVScale.x + .5f + UVOffset.x, v.y / UVScale.y + .5f + UVOffset.y));
        }

        foreach (Polygon2D hole in polygon.holesList)
        {
            pointsList   = new List <Vector2>();
            UVpointsList = new List <Vector2>();

            foreach (Vector2D p in hole.pointsList)
            {
                v.x = (float)p.x;
                v.y = (float)p.y;

                pointsList.Add(v);

                UVpointsList.Add(new Vector2(v.x / UVScale.x + .5f, v.y / UVScale.y + .5f));
            }

            poly.holes.Add(pointsList);
            poly.holesUVs.Add(UVpointsList);
        }

        return(TriangulationWrapper.CreateMesh(poly));
    }
    public static Mesh PerformTriangulationAdvanced(Polygon2D polygon, Vector2 UVScale, Vector2 UVOffset, float UVRotation)
    {
        TriangulationWrapper.Polygon poly = new TriangulationWrapper.Polygon();

        List <Vector2> pointsList   = null;
        List <Vector2> UVpointsList = null;

        Vector3 v = Vector3.zero;

        foreach (Vector2D p in polygon.pointsList)
        {
            v = p.ToVector2();
            poly.outside.Add(v);

            float distance = Mathf.Sqrt((v.x / UVScale.x) * (v.x / UVScale.x) + (v.y / UVScale.y) * (v.y / UVScale.y));
            float rotation = Mathf.Atan2(v.y / UVScale.y, v.x / UVScale.x);

            float x = Mathf.Cos(rotation + UVRotation * Mathf.Deg2Rad) * distance;
            float y = Mathf.Sin(rotation + UVRotation * Mathf.Deg2Rad) * distance;

            poly.outsideUVs.Add(new Vector2(x + .5f + UVOffset.x, y + .5f + UVOffset.y));
        }

        foreach (Polygon2D hole in polygon.holesList)
        {
            pointsList   = new List <Vector2> ();
            UVpointsList = new List <Vector2> ();

            foreach (Vector2D p in hole.pointsList)
            {
                v = p.ToVector2();
                pointsList.Add(v);
                UVpointsList.Add(new Vector2(v.x / UVScale.x + .5f + UVOffset.x, v.y / UVScale.y + .5f + UVOffset.y));
            }

            poly.holes.Add(pointsList);
            poly.holesUVs.Add(UVpointsList);
        }

        return(TriangulationWrapper.CreateMesh(poly));
    }
Пример #5
0
    public static Mesh TriangulateAdvanced(Polygon2 polygon, Vector2 UVScale, Vector2 UVOffset)
    {
        TriangulationWrapper.Polygon poly = new TriangulationWrapper.Polygon();

        //List<Vector2> pointsList = null;
        //List<Vector2> UVpointsList = null;

        Vector3 v = Vector3.zero;

        foreach (Vector2 p in polygon.points)
        {
            poly.outside.Add(p);
            //poly.outsideUVs.Add (new Vector2(v.x / UVScale.x + .5f + UVOffset.x, v.y / UVScale.y + .5f + UVOffset.y));

            poly.outsideUVs.Add(Vector2.zero);
        }

        /*
         * foreach (Polygon2D hole in polygon.holesList) {
         *      pointsList = new List<Vector2> ();
         *      UVpointsList = new List<Vector2> ();
         *
         *      foreach (Vector2D p in hole.pointsList) {
         *              v = p.ToVector2();
         *              pointsList.Add (v);
         *              //UVpointsList.Add (new Vector2(v.x / UVScale.x + .5f, v.y / UVScale.y + .5f));
         *
         *              UVpointsList.Add (Vector2.zero);
         *      }
         *
         *      poly.holes.Add (pointsList);
         *      poly.holesUVs.Add (UVpointsList);
         * }*/

        return(TriangulationWrapper.CreateMesh(poly));
    }
    public static Mesh PerformTriangulation(Polygon2D polygon, Vector2 UVScale, Vector2 UVOffset)
    {
        List <Vector2D> pointList = new List <Vector2D>(polygon.pointsList);

        // Optimize!!!
        Pair2D          pair   = new Pair2D(pointList.Last(), null);
        List <Vector2D> points = new List <Vector2D>(polygon.pointsList);

        for (int i = 0; i < points.Count; i++)
        {
            pair.B = points[i];

            if (points.Count < 4)
            {
                break;
            }

            if (Vector2D.Distance(pair.A, pair.B) < 0.005f)
            {
                //Debug.LogWarning("SmartUtilities2D: Polygon points are too close");
                polygon.pointsList.Remove(pair.A);
            }

            pair.A = pair.B;
        }

        TriangulationWrapper.Polygon poly = new TriangulationWrapper.Polygon();

        List <Vector2> pointsList   = null;
        List <Vector2> UVpointsList = null;

        Vector3 v = Vector3.zero;

        foreach (Vector2D p in polygon.pointsList)
        {
            v.x = (float)p.x;
            v.y = (float)p.y;

            poly.outside.Add(v);
            poly.outsideUVs.Add(new Vector2(v.x / UVScale.x + .5f + UVOffset.x, v.y / UVScale.y + .5f + UVOffset.y));
        }

        foreach (Polygon2D hole in polygon.holesList)
        {
            pointsList   = new List <Vector2>();
            UVpointsList = new List <Vector2>();

            foreach (Vector2D p in hole.pointsList)
            {
                v.x = (float)p.x;
                v.y = (float)p.y;

                pointsList.Add(v);

                UVpointsList.Add(new Vector2(v.x / UVScale.x + .5f, v.y / UVScale.y + .5f));
            }

            poly.holes.Add(pointsList);
            poly.holesUVs.Add(UVpointsList);
        }

        return(TriangulationWrapper.CreateMesh(poly));
    }