Exemple #1
0
        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));
        }
Exemple #2
0
        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));
        }