Exemple #1
0
        public static void Update()
        {
            if (!Dirty)
            {
                return;
            }
            Dirty = false;

            MeshVerts.Clear();

            for (int i = 0; i < VoxelArray.Length; i++)
            {
                IdxToPos(i, out int X, out int Y, out int Z);
                VoxelEntry T = VoxelEntry.Empty;

                if (Visible(T = GetVoxel(X, Y, Z)))
                {
                    if (!Visible(X + 1, Y, Z) || !Visible(X - 1, Y, Z) || !Visible(X, Y + 1, Z) || !Visible(X, Y - 1, Z) || !Visible(X, Y, Z + 1) || !Visible(X, Y, Z - 1))
                    {
                        EmitVoxel(T, X, Y, Z, MeshVerts);
                    }
                }
            }

            if (MeshVerts.Count > 0)
            {
                VoxMesh.SetVertices(MeshVerts.ToArray());
            }
        }
Exemple #2
0
        public static void SetVoxel(int X, int Y, int Z, VoxelEntry Vox)
        {
            if (X < 0 || X >= Width)
            {
                return;
            }

            if (Y < 0 || Y >= Height)
            {
                return;
            }

            if (Z < 0 || Z >= Depth)
            {
                return;
            }

            int Idx = PosToIdx(X, Y, Z);

            if (VoxelArray[Idx].Type != Vox.Type)
            {
                VoxelArray[Idx] = Vox;

                if (Program.MarkDirtyAuto)
                {
                    Dirty = true;
                }
            }
        }
Exemple #3
0
        public static void Update()
        {
            if (!Dirty)
            {
                return;
            }
            Dirty = false;

            MeshVerts.Clear();             // Clears the mesh

            for (int i = 0; i < VoxelArray.Length; i++)
            {
                IdxToPos(i, out int X, out int Y, out int Z);
                VoxelEntry T = VoxelEntry.Empty;

                if (Visible(T = GetVoxel(X, Y, Z)))
                {
                    //Check if the block can actually be visible. If not, we do not want to emit it.
                    if (!Visible(X + 1, Y, Z) || !Visible(X - 1, Y, Z) || !Visible(X, Y + 1, Z) || !Visible(X, Y - 1, Z) || !Visible(X, Y, Z + 1) || !Visible(X, Y, Z - 1))
                    {
                        EmitVoxel(T, X, Y, Z, MeshVerts);
                    }
                }
            }

            if (MeshVerts.Count > 0)
            {
                VoxMesh.SetVertices(MeshVerts.ToArray());
            }
        }
Exemple #4
0
        public static bool Visible(VoxelEntry T)
        {
            if (T.Type == VoxelType.Empty)
            {
                return(false);
            }

            return(true);
        }
Exemple #5
0
        public static bool IsSolid(VoxelEntry T)
        {
            if (T.Type == VoxelType.Solid)
            {
                return(true);
            }

            return(false);
        }
Exemple #6
0
        static void EmitVoxel(VoxelEntry T, int X, int Y, int Z, List <Vertex3> Verts)
        {
            for (int i = 0; i < CubeVerts.Length; i++)
            {
                Vertex3 V = CubeVerts[i];
                V.Position = (V.Position + new Vector3(0.5f) + new Vector3(X, Y, Z)) * VoxelSize;
                V.Color    = T.Color;

                Verts.Add(V);
            }
        }
Exemple #7
0
        public static void Fill(VoxelEntry Vox)
        {
            for (int i = 0; i < VoxelArray.Length; i++)
            {
                VoxelArray[i] = Vox;
            }

            if (Program.MarkDirtyAuto)
            {
                Dirty = true;
            }
        }
Exemple #8
0
 public static void SetVoxel(Vector3 WorldCoords, VoxelEntry Vox)
 {
     WorldCoordToPos(WorldCoords, out int X, out int Y, out int Z);
     SetVoxel(X, Y, Z, Vox);
 }