예제 #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());
            }
        }
예제 #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;
                }
            }
        }
예제 #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());
            }
        }
예제 #4
0
        public static bool Visible(VoxelEntry T)
        {
            if (T.Type == VoxelType.Empty)
            {
                return(false);
            }

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

            return(false);
        }
예제 #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);
            }
        }
예제 #7
0
        public static void Fill(VoxelEntry Vox)
        {
            for (int i = 0; i < VoxelArray.Length; i++)
            {
                VoxelArray[i] = Vox;
            }

            if (Program.MarkDirtyAuto)
            {
                Dirty = true;
            }
        }
예제 #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);
 }