Esempio n. 1
0
        public int AddFace(Face.Facing facing, float x, float y, float z, Vector3 size, ref Color color)
        {
            for (int i = 0; i < buffers.Count; i++)
            {
                if (!buffers[i].Full)
                {
                    int k = buffers[i].AddVertices(Face.getFace(facing, new Vector3(x, y, z), size, color.ToVector3()));

                    if (k > -1)
                    {
                        return((i * Size) + k);
                    }

                    return(-1);
                }
            }

            buffers.Add(new BatchBuffer(Size));

            int j = buffers[buffers.Count - 1].AddVertices(Face.getFace(facing, new Vector3(x, y, z), size, color.ToVector3()));

            if (j > -1)
            {
                return(((buffers.Count - 1) * Size) + j);
            }

            return(-1);
        }
Esempio n. 2
0
 public void AddFace(Face.Facing facing, Vector3 position, Vector3 color)
 {
     tmp = Face.getFace(facing, position, color);
     if (tmp == null)
     {
         return;
     }
     for (int i = 0; i < 6; i++)
     {
         vertices.Add(tmp[i]);
     }
     tmp = null;
 }
Esempio n. 3
0
        public void Add(Voxel voxel)
        {
            voxel.position -= this.Position;
            if (Voxels[(int)voxel.position.X, (int)voxel.position.Y, (int)voxel.position.Z] != null)
            {
                return;
            }
            //if (!inChunk(voxel.position)) return;
            //this.Remove(voxel);
            Voxels[(int)voxel.position.X, (int)voxel.position.Y, (int)voxel.position.Z] = voxel;

            if (((int)voxel.position.X + 1 < this.Size.X && Voxels[(int)voxel.position.X + 1, (int)voxel.position.Y, (int)voxel.position.Z] == null) || (int)voxel.position.X == this.Size.X - 1)
            {
                vertices.AddRange(Face.getFace(Face.Facing.Right, voxel.position, voxel.color));
            }

            if (((int)voxel.position.X - 1 >= 0 && Voxels[(int)voxel.position.X - 1, (int)voxel.position.Y, (int)voxel.position.Z] == null) || (int)voxel.position.X == 0)
            {
                vertices.AddRange(Face.getFace(Face.Facing.Left, voxel.position, voxel.color));
            }

            if (((int)voxel.position.Y + 1 < this.Size.Y && Voxels[(int)voxel.position.X, (int)voxel.position.Y + 1, (int)voxel.position.Z] == null) || (int)voxel.position.Y == this.Size.Y - 1)
            {
                vertices.AddRange(Face.getFace(Face.Facing.Up, voxel.position, voxel.color));
            }

            if (((int)voxel.position.Y - 1 >= 0 && Voxels[(int)voxel.position.X, (int)voxel.position.Y - 1, (int)voxel.position.Z] == null) || (int)voxel.position.Y == 0)
            {
                vertices.AddRange(Face.getFace(Face.Facing.Down, voxel.position, voxel.color));
            }

            if (((int)voxel.position.Z + 1 < this.Size.Z && Voxels[(int)voxel.position.X, (int)voxel.position.Y, (int)voxel.position.Z + 1] == null) || (int)voxel.position.Z == this.Size.Z - 1)
            {
                vertices.AddRange(Face.getFace(Face.Facing.Forward, voxel.position, voxel.color));
            }

            if (((int)voxel.position.Z - 1 >= 0 && Voxels[(int)voxel.position.X, (int)voxel.position.Y, (int)voxel.position.Z - 1] == null) || (int)voxel.position.Z == 0)
            {
                vertices.AddRange(Face.getFace(Face.Facing.Backward, voxel.position, voxel.color));
            }


            this.Build();
        }
Esempio n. 4
0
        public void BuildVertices()
        {
            vertices = new List <VertexPositionNormalColor>();
            foreach (Voxel voxel in Voxels)
            {
                if (voxel != null)
                {
                    if (((int)voxel.position.X + 1 < this.Size.X && Voxels[(int)voxel.position.X + 1, (int)voxel.position.Y, (int)voxel.position.Z] == null) || (int)voxel.position.X == this.Size.X - 1)
                    {
                        vertices.AddRange(Face.getFace(Face.Facing.Right, voxel.position, voxel.color));
                    }

                    if (((int)voxel.position.X - 1 >= 0 && Voxels[(int)voxel.position.X - 1, (int)voxel.position.Y, (int)voxel.position.Z] == null) || (int)voxel.position.X == 0)
                    {
                        vertices.AddRange(Face.getFace(Face.Facing.Left, voxel.position, voxel.color));
                    }

                    if (((int)voxel.position.Y + 1 < this.Size.Y && Voxels[(int)voxel.position.X, (int)voxel.position.Y + 1, (int)voxel.position.Z] == null) || (int)voxel.position.Y == this.Size.Y - 1)
                    {
                        vertices.AddRange(Face.getFace(Face.Facing.Up, voxel.position, voxel.color));
                    }

                    if (((int)voxel.position.Y - 1 >= 0 && Voxels[(int)voxel.position.X, (int)voxel.position.Y - 1, (int)voxel.position.Z] == null) || (int)voxel.position.Y == 0)
                    {
                        vertices.AddRange(Face.getFace(Face.Facing.Down, voxel.position, voxel.color));
                    }

                    if (((int)voxel.position.Z + 1 < this.Size.Z && Voxels[(int)voxel.position.X, (int)voxel.position.Y, (int)voxel.position.Z + 1] == null) || (int)voxel.position.Z == this.Size.Z - 1)
                    {
                        vertices.AddRange(Face.getFace(Face.Facing.Forward, voxel.position, voxel.color));
                    }

                    if (((int)voxel.position.Z - 1 >= 0 && Voxels[(int)voxel.position.X, (int)voxel.position.Y, (int)voxel.position.Z - 1] == null) || (int)voxel.position.Z == 0)
                    {
                        vertices.AddRange(Face.getFace(Face.Facing.Backward, voxel.position, voxel.color));
                    }
                }
            }
            Build();
        }
Esempio n. 5
0
        public void insertFace(Face.Facing facing, ref Voxel voxel)
        {
            List <VertexPositionNormalColor> faces = getVisibleFaces(voxel);

            // If empty, append the face to the end and exit;
            if (faces.Count() == 0)
            {
                VertexPositionNormalColor[] face = Face.getFace(facing, ref voxel);
                vertices.AddRange(face);
                return;
            }

            int index;

            // If faces don't exist in the visible vertices, exit. Something's wrong if so, and this should never occur.
            if ((index = getFaceIndex(ref faces)) == -1)
            {
                return;
            }


            for (int i = 0; i < faces.Count() - 6; i = i + 6)
            {
                if (facing < Face.getFacing(faces.GetRange(i, 6)))
                {
                    vertices.InsertRange(index + i, Face.getFace(facing, ref voxel));
                    return;
                }
            }
            try
            {
                vertices.InsertRange(index + 30, Face.getFace(facing, ref voxel));
            }
            catch (ArgumentOutOfRangeException e)
            {
            }
        }
Esempio n. 6
0
        public List <VertexPositionNormalColor> getVisibleFaces(int x, int y, int z)
        {
            List <VertexPositionNormalColor> faces = new List <VertexPositionNormalColor>();

            if ((x + 1 < this.Size.X && Voxels[x + 1, y, z] == null) || x + 1 == this.Size.X)
            {
                faces.AddRange(Face.getFace(Face.Facing.Right, Voxels[x, y, z].position, Voxels[x, y, z].color));
            }

            if ((x - 1 >= 0 && Voxels[x - 1, y, z] == null) || x == 0)
            {
                faces.AddRange(Face.getFace(Face.Facing.Left, Voxels[x, y, z].position, Voxels[x, y, z].color));
            }

            if ((y + 1 < this.Size.Y && Voxels[x, y + 1, z] == null) || y + 1 == this.Size.Y)
            {
                faces.AddRange(Face.getFace(Face.Facing.Up, Voxels[x, y, z].position, Voxels[x, y, z].color));
            }

            if ((y - 1 >= 0 && Voxels[x, y - 1, z] == null) || y == 0)
            {
                faces.AddRange(Face.getFace(Face.Facing.Down, Voxels[x, y, z].position, Voxels[x, y, z].color));
            }

            if ((z + 1 < this.Size.Z && Voxels[x, y, z + 1] == null) || z + 1 == this.Size.Z)
            {
                faces.AddRange(Face.getFace(Face.Facing.Forward, Voxels[x, y, z].position, Voxels[x, y, z].color));
            }

            if ((z - 1 >= 0 && Voxels[x, y, z - 1] == null) || z == 0)
            {
                faces.AddRange(Face.getFace(Face.Facing.Backward, Voxels[x, y, z].position, Voxels[x, y, z].color));
            }

            return(faces);
        }
Esempio n. 7
0
 public BasicFace(Face.Facing facing, Vector3 position, int size, Color color)
 {
     this.arrayPosition = 0;
     this.facing        = facing;
     vertices           = Face.getFace(facing, position, size, color.ToVector3());
 }