コード例 #1
0
        public override Vector3[] BuildNormals(
            ref int count,
            ref CullingFaces c, ref Voxel v,
            int x, int y, int z)
        {
            var l = 4 * (6 - ((byte)c).PopCount());

            count += l;

            var vertices = new Vector3[l];
            var index    = 0;

            for (byte f = 1; f <= (byte)CullingFaces.Down; f = (byte)(f << 1))
            {
                if (((byte)f).PopCount() != 1)
                {
                    continue;
                }
                if (!c.HasFlag(f))
                {
                    Array.Copy(
                        MakeFaceNormals((CullingFaces)f, x, y, z),
                        0,
                        vertices,
                        index,
                        4);
                    index += 4;
                }
            }

            return(vertices);
        }
コード例 #2
0
        private static IEnumerable <Vector3> MakeNormals(CullingFaces cullingFaces, int x, int y, int z)
        {
            var count = 4 * (6 - ((byte)cullingFaces).PopCount());

            var vertices = new Vector3[count];
            var index    = 0;

            foreach (var face in Enum.GetValues(typeof(CullingFaces)))
            {
                if (((byte)(CullingFaces)face).PopCount() != 1)
                {
                    continue;
                }
                if (!cullingFaces.HasFlag((CullingFaces)face))
                {
                    Array.Copy(
                        MakeFaceNormals((CullingFaces)face, x, y, z),
                        0,
                        vertices,
                        index,
                        4);
                    index += 4;
                }
            }

            return(vertices);
        }
コード例 #3
0
        public override Vector3[] BuildVertices(ref int count, ref CullingFaces c, ref Voxel v, int x, int y, int z)
        {
            var l = 4 * (6 - ((byte)c).PopCount());

            count += l;
            var vertices = new Vector3[l];
            var index    = 0;

            var o = new Vector3(x, y, z);

            // Faster itterate over culling faces against Enum.GetValues
            for (byte fi = 1 << 0; fi <= (byte)CullingFaces.Down; fi = (byte)(fi << 1))
            {
                if (!c.HasFlag(fi))
                {
                    Array.Copy(
                        MakeFaceVerts(fi, ref o),
                        0,
                        vertices,
                        index,
                        4);
                    index += 4;
                }
            }

            return(vertices);
        }
コード例 #4
0
        private static int[] MakeTriangles(CullingFaces face, ref int start)
        {
            var count     = 6 * (6 - ((byte)face).PopCount());
            var triangles = new int[count];
            var index     = 0;

            foreach (var f in Enum.GetValues(typeof(CullingFaces)))
            {
                if (((byte)(CullingFaces)f).PopCount() != 1)
                {
                    continue;
                }
                if (!face.HasFlag((CullingFaces)f))
                {
                    Array.Copy(MakeFaceTriangles((CullingFaces)f, start), 0, triangles, index, 6);
                    index += 6;
                    start += 4;
                }
            }

            return(triangles);
        }
コード例 #5
0
        public override int[] BuildTrianlges(ref int count, ref CullingFaces c, ref Voxel v, ref int triangleIndex, int x, int y, int z)
        {
            var l = 6 * (6 - ((byte)c).PopCount());

            count += l;
            var triangles = new int[l];
            var index     = 0;

            for (byte f = 1 << 0; f <= (byte)CullingFaces.Down; f = (byte)(f << 1))
            {
                if (((byte)f).PopCount() != 1)
                {
                    continue;
                }
                if (!c.HasFlag(f))
                {
                    Array.Copy(MakeFaceTriangles((CullingFaces)f, triangleIndex), 0, triangles, index, 6);
                    index         += 6;
                    triangleIndex += 4;
                }
            }

            return(triangles);
        }