public VoxelMesh MakeWaterMesh(Block[,] tile) { Vector3[] vertices; List <Vector2> uvs = new List <Vector2>(); int[] triangles; List <Color4> colors = new List <Color4>(); VoxelMesh mesh = new VoxelMesh(); int widh = MidleWorld.ChunkSize + 1; vertices = new Vector3[widh * widh]; for (int y = 0; y < widh; y++) { for (int x = 0; x < widh; x++) { vertices[x + y * widh] = new Vector3(x, 0.0f, y); colors.Add(new Color4(1, 1, 1, 1)); uvs.AddRange(AssetsManager.GetTileUV("Water")); } } triangles = new int[3 * 2 * (widh * widh - widh - widh + 1)]; int triangleVertexCount = 0; for (int vertex = 0; vertex < widh * widh - widh; vertex++) { if (vertex % widh != (widh - 1)) { // First triangle int A = vertex; int B = A + widh; int C = B + 1; triangles[triangleVertexCount] = A; triangles[triangleVertexCount + 1] = B; triangles[triangleVertexCount + 2] = C; //Second triangle B += 1; C = A + 1; triangles[triangleVertexCount + 3] = A; triangles[triangleVertexCount + 4] = B; triangles[triangleVertexCount + 5] = C; triangleVertexCount += 6; } } mesh.verts = vertices; mesh.uvs = uvs.ToArray(); mesh.indices = triangles; mesh.colors = colors.ToArray(); return(mesh); }
public VoxelMesh MakeWatersMehs(Block[,] tile) { _vertices = new List <Vector3>(); _UVs = new List <Vector2>(); _triangles = new List <int>(); _colors = new List <Color4>(); VoxelMesh mesh = new VoxelMesh(); int verticesNum = 0; for (int x = 0; x < MidleWorld.ChunkSize; x++) { for (int z = 0; z < MidleWorld.ChunkSize; z++) { if (tile[x, z].Type == TypeBlock.Sand) { _vertices.Add(new Vector3(x, -1f, z)); _vertices.Add(new Vector3(x + 1, -1, z)); _vertices.Add(new Vector3(x, -1, z + 1)); _vertices.Add(new Vector3(x + 1, -1, z + 1)); _triangles.Add(0 + verticesNum); _triangles.Add(1 + verticesNum); _triangles.Add(2 + verticesNum); _triangles.Add(2 + verticesNum); _triangles.Add(1 + verticesNum); _triangles.Add(3 + verticesNum); verticesNum += 4; _colors.Add(new Color4(1, 1, 1, 1)); _colors.Add(new Color4(1, 1, 1, 1)); _colors.Add(new Color4(1, 1, 1, 1)); _colors.Add(new Color4(1, 1, 1, 1)); _UVs.AddRange(AssetsManager.GetTileUV("Water")); } } } mesh.verts = _vertices.ToArray(); mesh.uvs = _UVs.ToArray(); mesh.indices = _triangles.ToArray(); mesh.colors = _colors.ToArray(); return(mesh); }
public MeshData(Block[,] tile) { _vertices = new List <Vector3>(); _UVs = new List <Vector2>(); _triangles = new List <int>(); _colors = new List <Color4>(); int verticesNum = 0; for (int x = 0; x < MidleWorld.ChunkSize; x++) { for (int z = 0; z < MidleWorld.ChunkSize; z++) { if (tile[x, z].Type != TypeBlock.Air) { int xB = tile[x, z].x; int zB = tile[x, z].z; float Right = GetTile(xB + 1, zB, tile[x, z].height, tile); float FrenteRight = GetTile(xB, zB + 1, tile[x, z].height, tile); float FrenteLeft = GetTile(xB + 1, zB + 1, tile[x, z].height, tile); _vertices.Add(new Vector3(x, tile[x, z].height, z)); _vertices.Add(new Vector3(x + 1, Right, z)); _vertices.Add(new Vector3(x, FrenteRight, z + 1)); _vertices.Add(new Vector3(x + 1, FrenteLeft, z + 1)); _triangles.Add(0 + verticesNum); _triangles.Add(1 + verticesNum); _triangles.Add(2 + verticesNum); _triangles.Add(2 + verticesNum); _triangles.Add(1 + verticesNum); _triangles.Add(3 + verticesNum); verticesNum += 4; _colors.Add(Get.TileColors(tile[x, z].TileBiome)); _colors.Add(Get.TileColors(tile[x, z].TileBiome)); _colors.Add(Get.TileColors(tile[x, z].TileBiome)); _colors.Add(Get.TileColors(tile[x, z].TileBiome)); _UVs.AddRange(AssetsManager.GetTileUV(tile[x, z].Type.ToString())); } } } }