List<TexturedVertex> GenerateVertsFor(VoxelContainer data, IntVector3 start, IntVector3 end)
    {
        var verts = new List<TexturedVertex>();
        var here = new IntVector3(data.Start);
        //Voxel currentVoxel;
        Vector3[] currentVerts;
        Vector2[] currentUVs;

        for (here.X = start.X; here.X <= end.X; here.X++)
            for (here.Z = start.Z; here.Z <= end.Z; here.Z++)
                for (here.Y = start.Y; here.Y <= end.Y; here.Y++)
                {
                    //currentVoxel = data.GetVoxel(here);
                    foreach (var face in VoxelHelper.VisibleFacesFor(data, here))
                    {
                        currentVerts = VoxelHelper.FaceVerts(here, face).ToArray();
                        currentUVs = VoxelHelper.UVCoords(data.GetVoxel(here).Type, face, Atlas).ToArray();

                        verts.AddRange(new []{
                            new TexturedVertex(currentVerts[0], currentUVs[0]),
                            new TexturedVertex(currentVerts[1], currentUVs[1]),
                            new TexturedVertex(currentVerts[2], currentUVs[2]),
                            new TexturedVertex(currentVerts[3], currentUVs[3])
                        });
                    }
                }

        return verts;
    }
示例#2
0
        /// <summary>
        /// Returns faces that are visible for the voxel at the given index in the given volume.
        /// </summary>
        /// <returns>The faces for.</returns>
        /// <param name="volume">Volume.</param>
        /// <param name="voxel">Voxel.</param>
        public static IEnumerable<Face> VisibleFacesFor(VoxelContainer chunk, IntVector3 voxel)
        {
            var result = new List<Face>();
            var faceVector = new IntVector3(voxel);

            if (chunk.GetVoxel(voxel).Weight > 0)
            {
                faceVector.Y += 1;
                if (chunk.GetVoxel(faceVector).Weight <= 0)
                    result.Add(Face.Top);

                faceVector.Y -= 2;
                if (chunk.GetVoxel(faceVector).Weight <= 0)
                    result.Add(Face.Bottom);

                faceVector.Y += 1;
                faceVector.X -= 1;
                if (chunk.GetVoxel(faceVector).Weight <= 0)
                    result.Add(Face.Left);

                faceVector.X += 2;
                if (chunk.GetVoxel(faceVector).Weight <= 0)
                    result.Add(Face.Right);

                faceVector.X -= 1;
                faceVector.Z -= 1;
                if (chunk.GetVoxel(faceVector).Weight <= 0)
                    result.Add(Face.Front);

                faceVector.Z += 2;
                if (chunk.GetVoxel(faceVector).Weight <= 0)
                    result.Add(Face.Back);
            }

            return result;
        }