Beispiel #1
0
        public static void triangulate(GameObject gameObject, Material material, List <ConnectedCoord> coords, float size)
        {
            List <int>            indices          = new List <int>();
            List <Vector3>        vertices         = new List <Vector3>();
            List <Color>          colors           = new List <Color>();
            List <CoordUnderside> processedCenters = new List <CoordUnderside>();

            foreach (ConnectedCoord coord in coords)
            {
                CoordUnderside        centerCoord        = coord.coord;
                List <CoordUnderside> neighbouringCoords = coord.neighbours.OrderBy(c => Math.Atan2(centerCoord.x - c.x, centerCoord.y - c.y)).ToList();
                if (neighbouringCoords.Count > 1)
                {
                    addTrianglesForCoord(centerCoord, neighbouringCoords, indices, vertices, colors);
                }

                processedCenters.Add(centerCoord);

                if (vertices.Count > vertexLimit)
                {
                    createMeshSubObject(gameObject, material, size, indices, vertices, colors);
                }
            }
            if (vertices.Count > 0)
            {
                createMeshSubObject(gameObject, material, size, indices, vertices, colors);
            }
        }
Beispiel #2
0
        private static void addTrianglesForCoord(CoordUnderside center,
                                                 List <CoordUnderside> corners,
                                                 List <int> indices,
                                                 List <Vector3> vertices,
                                                 List <Color> colors)
        {
            Vector3 vertexCenter = center.toVector3(1);

            for (int i = 0; i < corners.Count; i++)
            {
                CoordUnderside corner1 = corners[i];
                int            index2  = i + 1 >= corners.Count ? 0 : i + 1;
                CoordUnderside corner2 = corners[index2];

                Vector3 vertex1 = corner1.toVector3(1);
                Vector3 vertex2 = corner2.toVector3(1);
                addTriangle(vertexCenter, vertex1, vertex2, Color.grey, indices, vertices, colors);
            }
        }
Beispiel #3
0
        public Island(int islandId, List <Center> centers, Rect simpleExtents)
        {
            this.islandId      = islandId;
            this.centers       = centers;
            this.simpleExtents = simpleExtents;
            this.center        = new Vector3(simpleExtents.center.x, 0, simpleExtents.center.y);

            this.corners = new List <Corner>();
            foreach (Center c in centers)
            {
                foreach (Corner corner in c.corners)
                {
                    if (!corners.Contains(corner))
                    {
                        corners.Add(corner);
                    }
                }
            }
            List <Corner> rimCorners = corners.Where(c => c.isIslandRim).ToList();

            Coord[] cornerCoords    = rimCorners.Select(c => new Coord(c.coord.x, c.coord.elevation, c.coord.y)).ToArray();
            float   lowestRimCorner = cornerCoords.Aggregate((prev, next) => prev.elevation < next.elevation ? prev : next).elevation;

            Coord[] coords = centers.Select(c => new Coord(c.coord.x, -lowestRimCorner, c.coord.y)).ToArray();
            undersideCoords = new List <ConnectedCoord>(centers.Count);
            for (int i = 0; i < centers.Count; i++)
            {
                Center                center             = centers[i];
                CoordUnderside        centerCoord        = new CoordUnderside(coords[i], false);
                List <CoordUnderside> neighbouringCoords = center.neighbours
                                                           .Where(c => centers.Contains(c))
                                                           .Select(c => new CoordUnderside(coords[centers.IndexOf(c)], false))
                                                           .ToList();
                IEnumerable <CoordUnderside> neighbouringRimCoords = center.corners
                                                                     .Where(c => c.isIslandRim)
                                                                     .Select(c => new CoordUnderside(cornerCoords[rimCorners.IndexOf(c)], true));
                neighbouringCoords.AddRange(neighbouringRimCoords);
                undersideCoords.Add(new ConnectedCoord(centerCoord, neighbouringCoords));
            }
        }
 public ConnectedCoord(CoordUnderside coord, List <CoordUnderside> neighbours)
 {
     this.coord      = coord;
     this.neighbours = neighbours;
 }