Beispiel #1
0
        private static UnityMeshInfo GenerateChunkTerrainUnityMeshInfo(Position3D chunkPosition)
        {
            var chunkTilePosition = chunkPosition * ChunkSize;

            var vertices  = new List <Vector3>();
            var uvs       = new List <Vector2>();
            var triangles = new List <int>();

            for (var x = 0; x < ChunkSize.x; x++)
            {
                for (var z = 0; z < ChunkSize.z; z++)
                {
                    for (var y = 0; y < ChunkSize.y; y++)
                    {
                        var tilePosition = chunkTilePosition + new Position3D(x, y, z);
                        var tile         = Map.Instance.GetTile(tilePosition);

                        if (tile.TileType.Visible)
                        {
                            RenderUtil.AddCube(vertices, triangles, uvs, tilePosition);
                        }
                    }
                }
            }

            var position = new Vector3(chunkTilePosition.x * Tile.TileSize.x, chunkTilePosition.y * Tile.TileSize.y, chunkTilePosition.z * Tile.TileSize.z);

            return(new UnityMeshInfo(vertices.ToArray(), triangles.ToArray(), uvs.ToArray(), Color, position));
        }
Beispiel #2
0
        public static void AddSquareFaceXPositive(List <Vector3> vertices, List <int> triangles, List <Vector2> uvs, Vector3 cubePosition, Vector3 tileSize, Position2D textureTileOffset)
        {
            RenderUtil.AddTriangleVertice(vertices, triangles, cubePosition + new Vector3(tileSize.x, 0, 0));
            RenderUtil.addUv(uvs, 0, 0, textureTileOffset);
            RenderUtil.AddTriangleVertice(vertices, triangles, cubePosition + new Vector3(tileSize.x, tileSize.y, tileSize.z));
            RenderUtil.addUv(uvs, 1, 1, textureTileOffset);
            RenderUtil.AddTriangleVertice(vertices, triangles, cubePosition + new Vector3(tileSize.x, 0, tileSize.z));
            RenderUtil.addUv(uvs, 0, 1, textureTileOffset);

            RenderUtil.AddTriangleVertice(vertices, triangles, cubePosition + new Vector3(tileSize.x, 0, 0));
            RenderUtil.addUv(uvs, 0, 0, textureTileOffset);
            RenderUtil.AddTriangleVertice(vertices, triangles, cubePosition + new Vector3(tileSize.x, tileSize.y, 0));
            RenderUtil.addUv(uvs, 1, 0, textureTileOffset);
            RenderUtil.AddTriangleVertice(vertices, triangles, cubePosition + new Vector3(tileSize.x, tileSize.y, tileSize.z));
            RenderUtil.addUv(uvs, 1, 1, textureTileOffset);
        }