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()); } }
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; } } }
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()); } }
public static bool Visible(VoxelEntry T) { if (T.Type == VoxelType.Empty) { return(false); } return(true); }
public static bool IsSolid(VoxelEntry T) { if (T.Type == VoxelType.Solid) { return(true); } return(false); }
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); } }
public static void Fill(VoxelEntry Vox) { for (int i = 0; i < VoxelArray.Length; i++) { VoxelArray[i] = Vox; } if (Program.MarkDirtyAuto) { Dirty = true; } }
public static void SetVoxel(Vector3 WorldCoords, VoxelEntry Vox) { WorldCoordToPos(WorldCoords, out int X, out int Y, out int Z); SetVoxel(X, Y, Z, Vox); }