private static CullingFaces CalcCullingFaces(VoxelData voxels, int x, int y, int z)
        {
            var r = CullingFaces.All;

            if (!voxels.GetVoxel(x + 1, y, z).IsSolid)
            {
                r -= CullingFaces.East;
            }
            if (!voxels.GetVoxel(x - 1, y, z).IsSolid)
            {
                r -= CullingFaces.West;
            }
            if (!voxels.GetVoxel(x, y, z - 1).IsSolid)
            {
                r -= CullingFaces.South;
            }
            if (!voxels.GetVoxel(x, y, z + 1).IsSolid)
            {
                r -= CullingFaces.North;
            }
            if (!voxels.GetVoxel(x, y - 1, z).IsSolid)
            {
                r -= CullingFaces.Down;
            }
            if (!voxels.GetVoxel(x, y + 1, z).IsSolid)
            {
                r -= CullingFaces.Up;
            }

            return(r);
        }
        public static ThreadableMesh Build(VoxelData voxels)
        {
            List <Vector3> vertices  = new List <Vector3>();
            List <int>     triangles = new List <int>();
            int            triIndex  = 0;

            for (int y = 0; y < voxels.Height; y++)
            {
                for (int z = 0; z < voxels.Depth; z++)
                {
                    for (int x = 0; x < voxels.Width; x++)
                    {
                        var voxel = voxels.GetVoxel(x, y, z);
                        if (voxel.Color.a == 0)
                        {
                            continue;
                        }

                        // build
                        var cullingFaces = CalcCullingFaces(voxels, x, y, z);

                        if (cullingFaces == CullingFaces.All)
                        {
                            continue;
                        }

                        vertices.AddRange(MakeVertices(cullingFaces, x, y, z));
                        triangles.AddRange(MakeTriangles(cullingFaces, ref triIndex));
                    }
                }
            }

            var mesh = new ThreadableMesh();

            mesh.Vertices  = vertices.ToArray();
            mesh.Triangles = triangles.ToArray();

            return(mesh);
        }