private void MergeSimilarChunks(MapChunk chunk, string texture0, string texture1, string texture2, string texture3, Func<Vector4, Vector4> swizzle) { var similarChunks = chunks .Where(x => x.Texture0 == texture0 && x.Texture1 == texture1 && x.Texture2 == texture2 && x.Texture3 == texture3) .ToList(); //if (similarChunks.Count > 0) // System.Diagnostics.Debug.WriteLine("Found " + similarChunks.Count + " similar chunks."); foreach (var otherChunk in similarChunks) { for (int i = 0; i < otherChunk.Vertices.Count; i++) { var vertex = otherChunk.Vertices[i]; chunk.Vertices.Add(new MapVertex { Position = vertex.Position, TextureCoordinate = vertex.TextureCoordinate, TextureBlends = swizzle(vertex.TextureBlends) }); } chunks.Remove(otherChunk); } }
public void BuildChunks() { chunks.Clear(); MapChunk chunk; for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Height; y++) { var index = x + y * map.Width; if (index >= map.Tiles.Length) continue; var tile = map.Tiles[index]; if (tile == null) continue; float fx1 = scale * (x + 0); float fy1 = scale * (y + 0); float fx2 = scale * (x + 0.5f); float fy2 = scale * (y + 0.5f); float fx3 = scale * (x + 1); float fy3 = scale * (y + 1); float fz1 = scale * tile.Height; // --------- // |\ A | B /| // | \ | / | // | H\ | / | // | \|/ C | // |----+----| // |G /|\ D | // | / | \ | // | /F | E\ | // |/ | \| // --------- chunk = new MapChunk(); // H chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy2), new Vector2(0.0f, 0.5f), new Vector4(0.5f, 0.5f, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy3), new Vector2(0.0f, 0.0f), new Vector4(0.25f, 0.25f, 0.25f, 0.25f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy2), new Vector2(0.5f, 0.5f), new Vector4(1, 0, 0, 0))); // A chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy3), new Vector2(0.0f, 0.0f), new Vector4(0.25f, 0.25f, 0.25f, 0.25f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy3), new Vector2(0.5f, 0.0f), new Vector4(0.5f, 0, 0, 0.5f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy2), new Vector2(0.5f, 0.5f), new Vector4(1, 0, 0, 0))); chunk.Texture0 = tile.FloorTexture; chunk.Texture1 = tile.WallTexture; chunk.Texture2 = tile.WallTexture; chunk.Texture3 = tile.WallTexture; if (tile.Height == tile.Left.Height) chunk.Texture1 = tile.Left.FloorTexture; if (tile.Height == tile.Above.Left.Height) chunk.Texture2 = tile.Above.Left.FloorTexture; if (tile.Height == tile.Above.Height) chunk.Texture3 = tile.Above.FloorTexture; chunks.Add(chunk); chunk = new MapChunk(); // B chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy3), new Vector2(0.5f, 0.0f), new Vector4(0.5f, 0.5f, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy3), new Vector2(1.0f, 0.0f), new Vector4(0.25f, 0.25f, 0.25f, 0.25f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy2), new Vector2(0.5f, 0.5f), new Vector4(1, 0, 0, 0))); // C chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy3), new Vector2(1.0f, 0.0f), new Vector4(0.25f, 0.25f, 0.25f, 0.25f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy2), new Vector2(1.0f, 0.5f), new Vector4(0.5f, 0, 0, 0.5f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy2), new Vector2(0.5f, 0.5f), new Vector4(1, 0, 0, 0))); chunk.Texture0 = tile.FloorTexture; chunk.Texture1 = tile.WallTexture; chunk.Texture2 = tile.WallTexture; chunk.Texture3 = tile.WallTexture; if (tile.Height == tile.Above.Height) chunk.Texture1 = tile.Above.FloorTexture; if (tile.Height == tile.Above.Right.Height) chunk.Texture2 = tile.Above.Right.FloorTexture; if (tile.Height == tile.Right.Height) chunk.Texture3 = tile.Right.FloorTexture; chunks.Add(chunk); chunk = new MapChunk(); // D chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy2), new Vector2(1.0f, 0.5f), new Vector4(0.5f, 0.5f, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy1), new Vector2(1.0f, 1.0f), new Vector4(0.25f, 0.25f, 0.25f, 0.25f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy2), new Vector2(0.5f, 0.5f), new Vector4(1, 0, 0, 0))); // E chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy1), new Vector2(1.0f, 1.0f), new Vector4(0.25f, 0.25f, 0.25f, 0.25f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy1), new Vector2(0.5f, 1.0f), new Vector4(0.5f, 0, 0, 0.5f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy2), new Vector2(0.5f, 0.5f), new Vector4(1, 0, 0, 0))); chunk.Texture0 = tile.FloorTexture; chunk.Texture1 = tile.WallTexture; chunk.Texture2 = tile.WallTexture; chunk.Texture3 = tile.WallTexture; if (tile.Height == tile.Right.Height) chunk.Texture1 = tile.Right.FloorTexture; if (tile.Height == tile.Right.Below.Height) chunk.Texture2 = tile.Right.Below.FloorTexture; if (tile.Height == tile.Below.Height) chunk.Texture3 = tile.Below.FloorTexture; chunks.Add(chunk); chunk = new MapChunk(); // F chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy1), new Vector2(0.5f, 1.0f), new Vector4(0.5f, 0.5f, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy1), new Vector2(0.0f, 1.0f), new Vector4(0.25f, 0.25f, 0.25f, 0.25f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy2), new Vector2(0.5f, 0.5f), new Vector4(1, 0, 0, 0))); // G chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy1), new Vector2(0.0f, 1.0f), new Vector4(0.25f, 0.25f, 0.25f, 0.25f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy2), new Vector2(0.0f, 0.5f), new Vector4(0.5f, 0, 0, 0.5f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy2), new Vector2(0.5f, 0.5f), new Vector4(1, 0, 0, 0))); chunk.Texture0 = tile.FloorTexture; chunk.Texture1 = tile.WallTexture; chunk.Texture2 = tile.WallTexture; chunk.Texture3 = tile.WallTexture; if (tile.Height == tile.Below.Height) chunk.Texture1 = tile.Below.FloorTexture; if (tile.Height == tile.Below.Left.Height) chunk.Texture2 = tile.Below.Left.FloorTexture; if (tile.Height == tile.Left.Height) chunk.Texture3 = tile.Left.FloorTexture; chunks.Add(chunk); if (tile.Height > tile.Below.Height) { chunk = new MapChunk(); float fz2 = scale * (tile.Height - 0.25f); float fz3 = scale * (tile.Below.Height + 0.25f); float fz4 = scale * (tile.Below.Height); float v = tile.Height - tile.Below.Height - 1; // TOP chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy1), new Vector2(0.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy1), new Vector2(0.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz2, fy1), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy1), new Vector2(0.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy1), new Vector2(0.5f, 0.00f), new Vector4(0.5f, 0.5f, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz2, fy1), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); // MIDDLE chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy1), new Vector2(0.0f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy1), new Vector2(0.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz3, fy1), new Vector2(0.5f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy1), new Vector2(0.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz2, fy1), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz3, fy1), new Vector2(0.5f, 0.75f + v), new Vector4(1, 0, 0, 0))); // BOTTOM chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy1), new Vector2(0.0f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz3, fy1), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz4, fy1), new Vector2(0.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz3, fy1), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz4, fy1), new Vector2(0.5f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz4, fy1), new Vector2(0.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Texture0 = tile.WallTexture; chunk.Texture1 = tile.FloorTexture; chunk.Texture2 = tile.Below.FloorTexture; if (tile.Height == tile.Left.Height) chunk.Texture3 = tile.Left.FloorTexture; else chunk.Texture3 = tile.WallTexture; chunks.Add(chunk); chunk = new MapChunk(); // TOP chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy1), new Vector2(0.5f, 0.00f), new Vector4(0.5f, 0.5f, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy1), new Vector2(1.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz2, fy1), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy1), new Vector2(1.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy1), new Vector2(1.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz2, fy1), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); // MIDDLE chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz3, fy1), new Vector2(0.5f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz2, fy1), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy1), new Vector2(1.0f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz2, fy1), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy1), new Vector2(1.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy1), new Vector2(1.0f, 0.75f + v), new Vector4(1, 0, 0, 0))); // BOTTOM chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz4, fy1), new Vector2(0.5f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz3, fy1), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz4, fy1), new Vector2(1.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz3, fy1), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy1), new Vector2(1.0f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz4, fy1), new Vector2(1.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Texture0 = tile.WallTexture; chunk.Texture1 = tile.FloorTexture; chunk.Texture2 = tile.Below.FloorTexture; if (tile.Height == tile.Right.Height) chunk.Texture3 = tile.Right.FloorTexture; else chunk.Texture3 = tile.WallTexture; chunks.Add(chunk); } if (tile.Height > tile.Left.Height) { chunk = new MapChunk(); float fz2 = scale * (tile.Height - 0.25f); float fz3 = scale * (tile.Left.Height + 0.25f); float fz4 = scale * (tile.Left.Height); float v = tile.Height - tile.Left.Height - 1; // TOP chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy3), new Vector2(0.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy3), new Vector2(0.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy2), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy3), new Vector2(0.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy2), new Vector2(0.5f, 0.00f), new Vector4(0.5f, 0.5f, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy2), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); // MIDDLE chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy3), new Vector2(0.0f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy3), new Vector2(0.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy2), new Vector2(0.5f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy3), new Vector2(0.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy2), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy2), new Vector2(0.5f, 0.75f + v), new Vector4(1, 0, 0, 0))); // BOTTOM chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy3), new Vector2(0.0f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy2), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz4, fy3), new Vector2(0.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy2), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz4, fy2), new Vector2(0.5f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz4, fy3), new Vector2(0.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Texture0 = tile.WallTexture; chunk.Texture1 = tile.FloorTexture; chunk.Texture2 = tile.Left.FloorTexture; if (tile.Height == tile.Above.Height) chunk.Texture3 = tile.Above.FloorTexture; else chunk.Texture3 = tile.WallTexture; chunks.Add(chunk); chunk = new MapChunk(); // TOP chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy2), new Vector2(0.5f, 0.00f), new Vector4(0.5f, 0.5f, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy1), new Vector2(1.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy2), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy1), new Vector2(1.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy1), new Vector2(1.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy2), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); // MIDDLE chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy2), new Vector2(0.5f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy2), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy1), new Vector2(1.0f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy2), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy1), new Vector2(1.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy1), new Vector2(1.0f, 0.75f + v), new Vector4(1, 0, 0, 0))); // BOTTOM chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz4, fy2), new Vector2(0.5f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy2), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz4, fy1), new Vector2(1.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy2), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy1), new Vector2(1.0f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz4, fy1), new Vector2(1.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Texture0 = tile.WallTexture; chunk.Texture1 = tile.FloorTexture; chunk.Texture2 = tile.Left.FloorTexture; if (tile.Height == tile.Right.Height) chunk.Texture3 = tile.Below.FloorTexture; else chunk.Texture3 = tile.WallTexture; chunks.Add(chunk); } if (tile.Height > tile.Above.Height) { float fz2 = scale * (tile.Height - 0.25f); float fz3 = scale * (tile.Above.Height + 0.25f); float fz4 = scale * (tile.Above.Height); float v = tile.Height - tile.Above.Height - 1; chunk = new MapChunk(); // TOP chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz2, fy3), new Vector2(0.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy3), new Vector2(0.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy3), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy3), new Vector2(0.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz1, fy3), new Vector2(0.5f, 0.00f), new Vector4(0.5f, 0.5f, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy3), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); // MIDDLE chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz3, fy3), new Vector2(0.0f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz2, fy3), new Vector2(0.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy3), new Vector2(0.5f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz2, fy3), new Vector2(0.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz2, fy3), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy3), new Vector2(0.5f, 0.75f + v), new Vector4(1, 0, 0, 0))); // BOTTOM chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz3, fy3), new Vector2(0.0f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy3), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz4, fy3), new Vector2(0.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz3, fy3), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx1, fz4, fy3), new Vector2(0.5f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz4, fy3), new Vector2(0.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Texture0 = tile.WallTexture; chunk.Texture1 = tile.FloorTexture; chunk.Texture2 = tile.Above.FloorTexture; if (tile.Height == tile.Right.Height) chunk.Texture3 = tile.Right.FloorTexture; else chunk.Texture3 = tile.WallTexture; chunks.Add(chunk); chunk = new MapChunk(); // TOP chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy3), new Vector2(0.5f, 0.00f), new Vector4(0.5f, 0.5f, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy3), new Vector2(1.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy3), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz1, fy3), new Vector2(1.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz2, fy3), new Vector2(1.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy3), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); // MIDDLE chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy3), new Vector2(0.5f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy3), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz3, fy3), new Vector2(1.0f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy3), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz2, fy3), new Vector2(1.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz3, fy3), new Vector2(1.0f, 0.75f + v), new Vector4(1, 0, 0, 0))); // BOTTOM chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz4, fy3), new Vector2(0.5f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy3), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz4, fy3), new Vector2(1.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy3), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz3, fy3), new Vector2(1.0f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx2, fz4, fy3), new Vector2(1.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Texture0 = tile.WallTexture; chunk.Texture1 = tile.FloorTexture; chunk.Texture2 = tile.Above.FloorTexture; if (tile.Height == tile.Left.Height) chunk.Texture3 = tile.Left.FloorTexture; else chunk.Texture3 = tile.WallTexture; chunks.Add(chunk); } if (tile.Height > tile.Right.Height) { float fz2 = scale * (tile.Height - 0.25f); float fz3 = scale * (tile.Right.Height + 0.25f); float fz4 = scale * (tile.Right.Height); float v = tile.Height - tile.Right.Height - 1; chunk = new MapChunk(); // TOP chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy2), new Vector2(0.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy2), new Vector2(0.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy3), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy2), new Vector2(0.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy3), new Vector2(0.5f, 0.00f), new Vector4(0.5f, 0.5f, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy3), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); // MIDDLE chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy2), new Vector2(0.0f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy2), new Vector2(0.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy3), new Vector2(0.5f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy2), new Vector2(0.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy3), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy3), new Vector2(0.5f, 0.75f + v), new Vector4(1, 0, 0, 0))); // BOTTOM chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy2), new Vector2(0.0f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy3), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz4, fy2), new Vector2(0.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy3), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz4, fy3), new Vector2(0.5f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz4, fy2), new Vector2(0.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Texture0 = tile.WallTexture; chunk.Texture1 = tile.FloorTexture; chunk.Texture2 = tile.Right.FloorTexture; if (tile.Height == tile.Below.Height) chunk.Texture3 = tile.Below.FloorTexture; else chunk.Texture3 = tile.WallTexture; chunks.Add(chunk); chunk = new MapChunk(); // TOP chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy1), new Vector2(0.5f, 0.00f), new Vector4(0.5f, 0.5f, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy2), new Vector2(1.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy1), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz1, fy2), new Vector2(1.0f, 0.00f), new Vector4(0.33f, 0.33f, 0, 0.33f))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy2), new Vector2(1.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy1), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); // MIDDLE chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy1), new Vector2(0.5f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy1), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy2), new Vector2(1.0f, 0.75f + v), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy1), new Vector2(0.5f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz2, fy2), new Vector2(1.0f, 0.25f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy2), new Vector2(1.0f, 0.75f + v), new Vector4(1, 0, 0, 0))); // BOTTOM chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz4, fy1), new Vector2(0.5f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy1), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz4, fy2), new Vector2(1.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy1), new Vector2(0.5f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz3, fy2), new Vector2(1.0f, 0.75f), new Vector4(1, 0, 0, 0))); chunk.Vertices.Add(new MapVertex(new Vector3(fx3, fz4, fy2), new Vector2(1.0f, 1.00f), new Vector4(0.5f, 0, 0.5f, 0))); chunk.Texture0 = tile.WallTexture; chunk.Texture1 = tile.FloorTexture; chunk.Texture2 = tile.Right.FloorTexture; if (tile.Height == tile.Right.Height) chunk.Texture3 = tile.Above.FloorTexture; else chunk.Texture3 = tile.WallTexture; chunks.Add(chunk); } } } }