Ejemplo n.º 1
0
 public void DrawSigns(Camera camera)
 {
     if (m_nearTexts.Count > 0)
     {
         TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(m_renderTarget, useAlphaTest: false, 0, DepthStencilState.DepthRead, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp);
         foreach (TextData nearText in m_nearTexts)
         {
             if (nearText.TextureLocation.HasValue)
             {
                 int       cellValue = m_subsystemTerrain.Terrain.GetCellValue(nearText.Point.X, nearText.Point.Y, nearText.Point.Z);
                 int       num       = Terrain.ExtractContents(cellValue);
                 SignBlock signBlock = BlocksManager.Blocks[num] as SignBlock;
                 if (signBlock != null)
                 {
                     int       data = Terrain.ExtractData(cellValue);
                     BlockMesh signSurfaceBlockMesh = signBlock.GetSignSurfaceBlockMesh(data);
                     if (signSurfaceBlockMesh != null)
                     {
                         TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(nearText.Point.X, nearText.Point.Z);
                         if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1)
                         {
                             nearText.Light = Terrain.ExtractLight(cellValue);
                         }
                         float   num2              = LightingManager.LightIntensityByLightValue[nearText.Light];
                         Color   color             = new Color(num2, num2, num2);
                         float   x                 = 0f;
                         float   x2                = nearText.UsedTextureWidth / 128f;
                         float   x3                = (float)nearText.TextureLocation.Value / 32f;
                         float   x4                = ((float)nearText.TextureLocation.Value + nearText.UsedTextureHeight / 32f) / 32f;
                         Vector3 signSurfaceNormal = signBlock.GetSignSurfaceNormal(data);
                         Vector3 vector            = new Vector3(nearText.Point.X, nearText.Point.Y, nearText.Point.Z);
                         float   num3              = Vector3.Dot(camera.ViewPosition - (vector + new Vector3(0.5f)), signSurfaceNormal);
                         Vector3 v                 = MathUtils.Max(0.01f * num3, 0.005f) * signSurfaceNormal;
                         for (int i = 0; i < signSurfaceBlockMesh.Indices.Count / 3; i++)
                         {
                             BlockMeshVertex blockMeshVertex  = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3]];
                             BlockMeshVertex blockMeshVertex2 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 1]];
                             BlockMeshVertex blockMeshVertex3 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 2]];
                             Vector3         p  = blockMeshVertex.Position + vector + v;
                             Vector3         p2 = blockMeshVertex2.Position + vector + v;
                             Vector3         p3 = blockMeshVertex3.Position + vector + v;
                             Vector2         textureCoordinates  = blockMeshVertex.TextureCoordinates;
                             Vector2         textureCoordinates2 = blockMeshVertex2.TextureCoordinates;
                             Vector2         textureCoordinates3 = blockMeshVertex3.TextureCoordinates;
                             textureCoordinates.X  = MathUtils.Lerp(x, x2, textureCoordinates.X);
                             textureCoordinates2.X = MathUtils.Lerp(x, x2, textureCoordinates2.X);
                             textureCoordinates3.X = MathUtils.Lerp(x, x2, textureCoordinates3.X);
                             textureCoordinates.Y  = MathUtils.Lerp(x3, x4, textureCoordinates.Y);
                             textureCoordinates2.Y = MathUtils.Lerp(x3, x4, textureCoordinates2.Y);
                             textureCoordinates3.Y = MathUtils.Lerp(x3, x4, textureCoordinates3.Y);
                             texturedBatch3D.QueueTriangle(p, p2, p3, textureCoordinates, textureCoordinates2, textureCoordinates3, color);
                         }
                     }
                 }
             }
         }
         m_primitivesRenderer3D.Flush(camera.ViewProjectionMatrix);
     }
 }
Ejemplo n.º 2
0
        public void AppendImageExtrusion(Image image, Rectangle bounds, Vector3 size, Color color)
        {
            BlockMesh blockMesh = new BlockMesh();
            DynamicArray <BlockMeshVertex> vertices = blockMesh.Vertices;
            DynamicArray <ushort>          indices  = blockMesh.Indices;
            BlockMeshVertex item = new BlockMeshVertex
            {
                Position           = new Vector3(bounds.Left, bounds.Top, -1f),
                TextureCoordinates = new Vector2(bounds.Left, bounds.Top)
            };

            vertices.Add(item);
            item = new BlockMeshVertex
            {
                Position           = new Vector3(bounds.Right, bounds.Top, -1f),
                TextureCoordinates = new Vector2(bounds.Right, bounds.Top)
            };
            vertices.Add(item);
            item = new BlockMeshVertex
            {
                Position           = new Vector3(bounds.Left, bounds.Bottom, -1f),
                TextureCoordinates = new Vector2(bounds.Left, bounds.Bottom)
            };
            vertices.Add(item);
            item = new BlockMeshVertex
            {
                Position           = new Vector3(bounds.Right, bounds.Bottom, -1f),
                TextureCoordinates = new Vector2(bounds.Right, bounds.Bottom)
            };
            vertices.Add(item);
            indices.Add((ushort)(vertices.Count - 4));
            indices.Add((ushort)(vertices.Count - 1));
            indices.Add((ushort)(vertices.Count - 3));
            indices.Add((ushort)(vertices.Count - 1));
            indices.Add((ushort)(vertices.Count - 4));
            indices.Add((ushort)(vertices.Count - 2));
            item = new BlockMeshVertex
            {
                Position           = new Vector3(bounds.Left, bounds.Top, 1f),
                TextureCoordinates = new Vector2(bounds.Left, bounds.Top)
            };
            vertices.Add(item);
            item = new BlockMeshVertex
            {
                Position           = new Vector3(bounds.Right, bounds.Top, 1f),
                TextureCoordinates = new Vector2(bounds.Right, bounds.Top)
            };
            vertices.Add(item);
            item = new BlockMeshVertex
            {
                Position           = new Vector3(bounds.Left, bounds.Bottom, 1f),
                TextureCoordinates = new Vector2(bounds.Left, bounds.Bottom)
            };
            vertices.Add(item);
            item = new BlockMeshVertex
            {
                Position           = new Vector3(bounds.Right, bounds.Bottom, 1f),
                TextureCoordinates = new Vector2(bounds.Right, bounds.Bottom)
            };
            vertices.Add(item);
            indices.Add((ushort)(vertices.Count - 4));
            indices.Add((ushort)(vertices.Count - 3));
            indices.Add((ushort)(vertices.Count - 1));
            indices.Add((ushort)(vertices.Count - 1));
            indices.Add((ushort)(vertices.Count - 2));
            indices.Add((ushort)(vertices.Count - 4));
            for (int i = bounds.Left - 1; i <= bounds.Right; i++)
            {
                int num = -1;
                for (int j = bounds.Top - 1; j <= bounds.Bottom; j++)
                {
                    bool num2 = !bounds.Contains(new Point2(i, j)) || image.GetPixel(i, j) == Color.Transparent;
                    bool flag = bounds.Contains(new Point2(i - 1, j)) && image.GetPixel(i - 1, j) != Color.Transparent;
                    if (num2 & flag)
                    {
                        if (num < 0)
                        {
                            num = j;
                        }
                    }
                    else if (num >= 0)
                    {
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)i - 0.01f, (float)num - 0.01f, -1.01f),
                            TextureCoordinates = new Vector2((float)(i - 1) + 0.01f, (float)num + 0.01f)
                        };
                        vertices.Add(item);
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)i - 0.01f, (float)num - 0.01f, 1.01f),
                            TextureCoordinates = new Vector2((float)i - 0.01f, (float)num + 0.01f)
                        };
                        vertices.Add(item);
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)i - 0.01f, (float)j + 0.01f, -1.01f),
                            TextureCoordinates = new Vector2((float)(i - 1) + 0.01f, (float)j - 0.01f)
                        };
                        vertices.Add(item);
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)i - 0.01f, (float)j + 0.01f, 1.01f),
                            TextureCoordinates = new Vector2((float)i - 0.01f, (float)j - 0.01f)
                        };
                        vertices.Add(item);
                        indices.Add((ushort)(vertices.Count - 4));
                        indices.Add((ushort)(vertices.Count - 1));
                        indices.Add((ushort)(vertices.Count - 3));
                        indices.Add((ushort)(vertices.Count - 1));
                        indices.Add((ushort)(vertices.Count - 4));
                        indices.Add((ushort)(vertices.Count - 2));
                        num = -1;
                    }
                }
            }
            for (int k = bounds.Left - 1; k <= bounds.Right; k++)
            {
                int num3 = -1;
                for (int l = bounds.Top - 1; l <= bounds.Bottom; l++)
                {
                    bool num4  = !bounds.Contains(new Point2(k, l)) || image.GetPixel(k, l) == Color.Transparent;
                    bool flag2 = bounds.Contains(new Point2(k + 1, l)) && image.GetPixel(k + 1, l) != Color.Transparent;
                    if (num4 & flag2)
                    {
                        if (num3 < 0)
                        {
                            num3 = l;
                        }
                    }
                    else if (num3 >= 0)
                    {
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)(k + 1) + 0.01f, (float)num3 - 0.01f, -1.01f),
                            TextureCoordinates = new Vector2((float)(k + 1) + 0.01f, (float)num3 + 0.01f)
                        };
                        vertices.Add(item);
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)(k + 1) + 0.01f, (float)num3 - 0.01f, 1.01f),
                            TextureCoordinates = new Vector2((float)(k + 2) - 0.01f, (float)num3 + 0.01f)
                        };
                        vertices.Add(item);
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)(k + 1) + 0.01f, (float)l + 0.01f, -1.01f),
                            TextureCoordinates = new Vector2((float)(k + 1) + 0.01f, (float)l - 0.01f)
                        };
                        vertices.Add(item);
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)(k + 1) + 0.01f, (float)l + 0.01f, 1.01f),
                            TextureCoordinates = new Vector2((float)(k + 2) - 0.01f, (float)l - 0.01f)
                        };
                        vertices.Add(item);
                        indices.Add((ushort)(vertices.Count - 4));
                        indices.Add((ushort)(vertices.Count - 3));
                        indices.Add((ushort)(vertices.Count - 1));
                        indices.Add((ushort)(vertices.Count - 1));
                        indices.Add((ushort)(vertices.Count - 2));
                        indices.Add((ushort)(vertices.Count - 4));
                        num3 = -1;
                    }
                }
            }
            for (int m = bounds.Top - 1; m <= bounds.Bottom; m++)
            {
                int num5 = -1;
                for (int n = bounds.Left - 1; n <= bounds.Right; n++)
                {
                    bool num6  = !bounds.Contains(new Point2(n, m)) || image.GetPixel(n, m) == Color.Transparent;
                    bool flag3 = bounds.Contains(new Point2(n, m - 1)) && image.GetPixel(n, m - 1) != Color.Transparent;
                    if (num6 & flag3)
                    {
                        if (num5 < 0)
                        {
                            num5 = n;
                        }
                    }
                    else if (num5 >= 0)
                    {
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)num5 - 0.01f, (float)m - 0.01f, -1.01f),
                            TextureCoordinates = new Vector2((float)num5 + 0.01f, (float)(m - 1) + 0.01f)
                        };
                        vertices.Add(item);
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)num5 - 0.01f, (float)m - 0.01f, 1.01f),
                            TextureCoordinates = new Vector2((float)num5 + 0.01f, (float)m - 0.01f)
                        };
                        vertices.Add(item);
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)n + 0.01f, (float)m - 0.01f, -1.01f),
                            TextureCoordinates = new Vector2((float)n - 0.01f, (float)(m - 1) + 0.01f)
                        };
                        vertices.Add(item);
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)n + 0.01f, (float)m - 0.01f, 1.01f),
                            TextureCoordinates = new Vector2((float)n - 0.01f, (float)m - 0.01f)
                        };
                        vertices.Add(item);
                        indices.Add((ushort)(vertices.Count - 4));
                        indices.Add((ushort)(vertices.Count - 3));
                        indices.Add((ushort)(vertices.Count - 1));
                        indices.Add((ushort)(vertices.Count - 1));
                        indices.Add((ushort)(vertices.Count - 2));
                        indices.Add((ushort)(vertices.Count - 4));
                        num5 = -1;
                    }
                }
            }
            for (int num7 = bounds.Top - 1; num7 <= bounds.Bottom; num7++)
            {
                int num8 = -1;
                for (int num9 = bounds.Left - 1; num9 <= bounds.Right; num9++)
                {
                    bool num10 = !bounds.Contains(new Point2(num9, num7)) || image.GetPixel(num9, num7) == Color.Transparent;
                    bool flag4 = bounds.Contains(new Point2(num9, num7 + 1)) && image.GetPixel(num9, num7 + 1) != Color.Transparent;
                    if (num10 & flag4)
                    {
                        if (num8 < 0)
                        {
                            num8 = num9;
                        }
                    }
                    else if (num8 >= 0)
                    {
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)num8 - 0.01f, (float)(num7 + 1) + 0.01f, -1.01f),
                            TextureCoordinates = new Vector2((float)num8 + 0.01f, (float)(num7 + 1) + 0.01f)
                        };
                        vertices.Add(item);
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)num8 - 0.01f, (float)(num7 + 1) + 0.01f, 1.01f),
                            TextureCoordinates = new Vector2((float)num8 + 0.01f, (float)(num7 + 2) - 0.01f)
                        };
                        vertices.Add(item);
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)num9 + 0.01f, (float)(num7 + 1) + 0.01f, -1.01f),
                            TextureCoordinates = new Vector2((float)num9 - 0.01f, (float)(num7 + 1) + 0.01f)
                        };
                        vertices.Add(item);
                        item = new BlockMeshVertex
                        {
                            Position           = new Vector3((float)num9 + 0.01f, (float)(num7 + 1) + 0.01f, 1.01f),
                            TextureCoordinates = new Vector2((float)num9 - 0.01f, (float)(num7 + 2) - 0.01f)
                        };
                        vertices.Add(item);
                        indices.Add((ushort)(vertices.Count - 4));
                        indices.Add((ushort)(vertices.Count - 1));
                        indices.Add((ushort)(vertices.Count - 3));
                        indices.Add((ushort)(vertices.Count - 1));
                        indices.Add((ushort)(vertices.Count - 4));
                        indices.Add((ushort)(vertices.Count - 2));
                        num8 = -1;
                    }
                }
            }
            for (int num11 = 0; num11 < vertices.Count; num11++)
            {
                vertices.Array[num11].Position.X           -= (float)bounds.Left + (float)bounds.Width / 2f;
                vertices.Array[num11].Position.Y            = (float)bounds.Bottom - vertices.Array[num11].Position.Y - (float)bounds.Height / 2f;
                vertices.Array[num11].Position.X           *= size.X / (float)bounds.Width;
                vertices.Array[num11].Position.Y           *= size.Y / (float)bounds.Height;
                vertices.Array[num11].Position.Z           *= size.Z / 2f;
                vertices.Array[num11].TextureCoordinates.X /= image.Width;
                vertices.Array[num11].TextureCoordinates.Y /= image.Height;
                vertices.Array[num11].Color = color;
            }
            AppendBlockMesh(blockMesh);
        }
Ejemplo n.º 3
0
        public void AppendModelMeshPart(ModelMeshPart meshPart, Matrix matrix, bool makeEmissive, bool flipWindingOrder, bool doubleSided, bool flipNormals, Color color)
        {
            VertexBuffer vertexBuffer = meshPart.VertexBuffer;
            IndexBuffer  indexBuffer  = meshPart.IndexBuffer;
            ReadOnlyList <VertexElement> vertexElements = vertexBuffer.VertexDeclaration.VertexElements;

            if (vertexElements.Count != 3 || vertexElements[0].Offset != 0 || vertexElements[0].Semantic != VertexElementSemantic.Position.GetSemanticString() || vertexElements[1].Offset != 12 || vertexElements[1].Semantic != VertexElementSemantic.Normal.GetSemanticString() || vertexElements[2].Offset != 24 || vertexElements[2].Semantic != VertexElementSemantic.TextureCoordinate.GetSemanticString())
            {
                throw new InvalidOperationException("Wrong vertex format for a block mesh.");
            }
            publicVertex[] vertexData = GetVertexData <publicVertex>(vertexBuffer);
            ushort[]       indexData  = GetIndexData <ushort>(indexBuffer);
            Dictionary <ushort, ushort> dictionary = new Dictionary <ushort, ushort>();

            for (int i = meshPart.StartIndex; i < meshPart.StartIndex + meshPart.IndicesCount; i++)
            {
                ushort num = indexData[i];
                if (!dictionary.ContainsKey(num))
                {
                    dictionary.Add(num, (ushort)Vertices.Count);
                    BlockMeshVertex item = default(BlockMeshVertex);
                    item.Position           = Vector3.Transform(vertexData[num].Position, matrix);
                    item.TextureCoordinates = vertexData[num].TextureCoordinate;
                    Vector3 vector = Vector3.Normalize(Vector3.TransformNormal(flipNormals ? (-vertexData[num].Normal) : vertexData[num].Normal, matrix));
                    if (makeEmissive)
                    {
                        item.IsEmissive = true;
                        item.Color      = color;
                    }
                    else
                    {
                        item.Color   = color * LightingManager.CalculateLighting(vector);
                        item.Color.A = color.A;
                    }
                    item.Face = (byte)CellFace.Vector3ToFace(vector);
                    Vertices.Add(item);
                }
            }
            for (int j = 0; j < meshPart.IndicesCount / 3; j++)
            {
                if (doubleSided)
                {
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 1]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 2]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 2]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 1]]);
                }
                else if (flipWindingOrder)
                {
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 2]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 1]]);
                }
                else
                {
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 1]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 2]]);
                }
            }
            Trim();
        }
Ejemplo n.º 4
0
        public static void DrawMeshBlock(PrimitivesRenderer3D primitivesRenderer, BlockMesh blockMesh, Texture2D texture, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {
            environmentData = (environmentData ?? m_defaultEnvironmentData);
            float   num = LightingManager.LightIntensityByLightValue[environmentData.Light];
            Vector4 v   = new Vector4(color);

            v.X *= num;
            v.Y *= num;
            v.Z *= num;
            bool            flag            = v == Vector4.One;
            TexturedBatch3D texturedBatch3D = primitivesRenderer.TexturedBatch(texture, useAlphaTest: true, 0, null, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp);
            bool            flag2           = false;
            Matrix          m = (!environmentData.ViewProjectionMatrix.HasValue) ? matrix : (matrix * environmentData.ViewProjectionMatrix.Value);

            if (size != 1f)
            {
                m = Matrix.CreateScale(size) * m;
            }
            if (m.M14 != 0f || m.M24 != 0f || m.M34 != 0f || m.M44 != 1f)
            {
                flag2 = true;
            }
            int count = blockMesh.Vertices.Count;

            BlockMeshVertex[] array = blockMesh.Vertices.Array;
            int count2 = blockMesh.Indices.Count;

            ushort[] array2 = blockMesh.Indices.Array;
            DynamicArray <VertexPositionColorTexture> triangleVertices = texturedBatch3D.TriangleVertices;
            int count3 = triangleVertices.Count;
            int count4 = triangleVertices.Count;

            triangleVertices.Count += count;
            for (int i = 0; i < count; i++)
            {
                BlockMeshVertex blockMeshVertex = array[i];
                if (flag2)
                {
                    Vector4 v2 = new Vector4(blockMeshVertex.Position, 1f);
                    Vector4.Transform(ref v2, ref m, out v2);
                    float num2 = 1f / v2.W;
                    blockMeshVertex.Position = new Vector3(v2.X * num2, v2.Y * num2, v2.Z * num2);
                }
                else
                {
                    Vector3.Transform(ref blockMeshVertex.Position, ref m, out blockMeshVertex.Position);
                }
                if (flag || blockMeshVertex.IsEmissive)
                {
                    triangleVertices.Array[count4++] = new VertexPositionColorTexture(blockMeshVertex.Position, blockMeshVertex.Color, blockMeshVertex.TextureCoordinates);
                    continue;
                }
                Color color2 = new Color((byte)((float)(int)blockMeshVertex.Color.R * v.X), (byte)((float)(int)blockMeshVertex.Color.G * v.Y), (byte)((float)(int)blockMeshVertex.Color.B * v.Z), (byte)((float)(int)blockMeshVertex.Color.A * v.W));
                triangleVertices.Array[count4++] = new VertexPositionColorTexture(blockMeshVertex.Position, color2, blockMeshVertex.TextureCoordinates);
            }
            DynamicArray <ushort> triangleIndices = texturedBatch3D.TriangleIndices;
            int count5 = triangleIndices.Count;

            triangleIndices.Count += count2;
            for (int j = 0; j < count2; j++)
            {
                triangleIndices.Array[count5++] = (ushort)(count3 + array2[j]);
            }
        }
Ejemplo n.º 5
0
        public override void Initialize()
        {
            base.Initialize();
            var mesh     = new BlockMesh();
            var vertices = new[]
            {
                new BlockMeshVertex
                {
                    Color = Color.White,
                    TextureCoordinates = new Vector2(0, 0.0625f),
                    Position           = new Vector3(0, 0.01f, 1)
                },
                new BlockMeshVertex
                {
                    Color = Color.White,
                    TextureCoordinates = new Vector2(0.0625f, 0.0625f),
                    Position           = new Vector3(1, 0.01f, 1)
                },
                new BlockMeshVertex
                {
                    Color = Color.White,
                    TextureCoordinates = new Vector2(0.0625f, 0),
                    Position           = new Vector3(1, 0.01f, 0)
                },
                new BlockMeshVertex
                {
                    Color = Color.White,
                    TextureCoordinates = new Vector2(0, 0),
                    Position           = new Vector3(0, 0.01f, 0)
                }
            };
            var indices = new ushort[] { 2, 1, 0, 0, 3, 2 };

            mesh.Vertices.AddRange(vertices);
            mesh.Indices.AddRange(indices);

            var flatMesh = new BlockMesh();

            flatMesh.AppendBlockMesh(mesh);
            flatMesh.TransformTextureCoordinates(Matrix.CreateTranslation(new Vector3(238 % 16 / 16f, 238 / 16 / 16f, 0f)));

            var center        = Matrix.CreateTranslation(new Vector3(0.5f, 0, 0.5f));
            var reverseCenter = Matrix.CreateTranslation(new Vector3(-0.5f, 0, -0.5f));

            for (int i = 0; i < 4; i++)
            {
                m_blockMeshes[i] = new BlockMesh();
                m_blockMeshes[i].AppendBlockMesh(flatMesh);
                m_blockMeshes[i].TransformPositions(reverseCenter * Matrix.CreateRotationY(MathUtils.PI * 0.5f * i) * center);
                m_blockMeshes[i].GenerateSidesData();
            }

            flatMesh = new BlockMesh();
            flatMesh.AppendBlockMesh(mesh);
            flatMesh.TransformTextureCoordinates(Matrix.CreateTranslation(new Vector3(237 % 16 / 16f, 237 / 16 / 16f, 0f)));

            m_blockMeshes[4] = new BlockMesh();
            m_blockMeshes[4].AppendBlockMesh(flatMesh);
            m_blockMeshes[4].GenerateSidesData();

            m_blockMeshes[5] = new BlockMesh();
            m_blockMeshes[5].AppendBlockMesh(flatMesh);
            m_blockMeshes[5].TransformPositions(reverseCenter * Matrix.CreateRotationY(MathUtils.PI * 0.5f) * center);
            m_blockMeshes[5].GenerateSidesData();

            mesh     = new BlockMesh();
            vertices = new BlockMeshVertex[]
            {
                new BlockMeshVertex
                {
                    Color = Color.White,
                    TextureCoordinates = new Vector2(0, 0.0625f),
                    Position           = new Vector3(0, 0.01f, 1)
                },
                new BlockMeshVertex
                {
                    Color = Color.White,
                    TextureCoordinates = new Vector2(0.0625f, 0.0625f),
                    Position           = new Vector3(1, 0.01f, 1)
                },
                new BlockMeshVertex
                {
                    Color = Color.White,
                    TextureCoordinates = new Vector2(0.0625f, 0),
                    Position           = new Vector3(1, 1.01f, 0)
                },
                new BlockMeshVertex
                {
                    Color = Color.White,
                    TextureCoordinates = new Vector2(0, 0),
                    Position           = new Vector3(0, 1.01f, 0)
                }
            };
            indices = new ushort[] { 2, 1, 0, 0, 1, 2, 0, 3, 2, 2, 3, 0 };
            mesh.Vertices.AddRange(vertices);
            mesh.Indices.AddRange(indices);
            mesh.TransformTextureCoordinates(Matrix.CreateTranslation(new Vector3(237 % 16 / 16f, 237 / 16 / 16f, 0f)));

            for (int i = 6; i < 10; i++)
            {
                m_blockMeshes[i] = new BlockMesh();
                m_blockMeshes[i].AppendBlockMesh(mesh);
                m_blockMeshes[i].TransformPositions(reverseCenter * Matrix.CreateRotationY(MathUtils.PI * 0.5f * i) * center);
            }

            var boxes = new []
            {
                new BoundingBox(0, 0, 0, 1, 0.01f, 1)
            };

            for (int i = 0; i < 6; i++)
            {
                boundingBoxes[i] = boxes;
            }
            boundingBoxes[6] = new BoundingBox[]
            {
                new BoundingBox(0, 0, 0, 1, 0.01f, 1),
                new BoundingBox(0, 0, 0.25f, 1, 0.25f, 1),
                new BoundingBox(0, 0, 0.5f, 1, 0.5f, 1),
                new BoundingBox(0, 0, 0.75f, 1, 0.75f, 1)
            };
            boundingBoxes[7] = new BoundingBox[]
            {
                new BoundingBox(0, 0, 0, 1, 0.01f, 1),
                new BoundingBox(0.25f, 0, 0, 1, 0.25f, 1),
                new BoundingBox(0.5f, 0, 0, 1, 0.5f, 1),
                new BoundingBox(0.75f, 0, 0, 1, 0.75f, 1)
            };
            boundingBoxes[8] = new BoundingBox[]
            {
                new BoundingBox(0, 0, 0, 1, 0.01f, 1),
                new BoundingBox(0, 0, 0, 1, 0.25f, 0.75f),
                new BoundingBox(0, 0, 0, 1, 0.5f, 0.5f),
                new BoundingBox(0, 0, 0, 1, 0.75f, 0.25f)
            };
            boundingBoxes[9] = new BoundingBox[]
            {
                new BoundingBox(0, 0, 0, 1, 0.01f, 1),
                new BoundingBox(0, 0, 0, 0.75f, 0.25f, 1),
                new BoundingBox(0, 0, 0, 0.5f, 0.5f, 1),
                new BoundingBox(0, 0, 0, 0.25f, 0.75f, 1)
            };
        }