/// <summary> /// Set or remove a voxel /// </summary> /// <param name="v">Index 0 will clear the voxel</param> public void SetVoxel(Voxel v) { if (v.X <= this.X && v.Y <= this.Y && v.Z <= this.Z) { string key = v.GetKey(); // Set if (v.Index != 0) { if (!Voxels.ContainsKey(key)) { VCount++; } Voxels[key] = v; } // Clear else { if (Voxels.ContainsKey(key)) { VCount--; } Voxels.Remove(key); } } }
/// <summary> /// Set or remove a voxel /// </summary> /// <param name="colorIndex">Number 0 will clear the voxel</param> public void SetVoxel(int x, int y, int z, byte colorIndex) { if (x >= 0 && y >= 0 && z >= 0 && x < this.X && y < this.Y && z < this.Z) { string key = x + "_" + y + "_" + z; // Set if (colorIndex != 0) { if (!Voxels.ContainsKey(key)) { VCount++; } Voxels[key] = colorIndex; } // Clear else { if (Voxels.ContainsKey(key)) { VCount--; } Voxels.Remove(key); } } }
public void Add(ulong x, ulong y, ulong z, byte c) { ulong f = Fuse(x, y, z); if (Voxels.ContainsKey(f)) { Voxels[f] = c; } else { Voxels.Add(f, c); Full.Add(f); } }
/** * Resets the order of potentially-visible voxels as used by the rotation-related methods; since this order is not * changed by normal {@link #Add(int, byte)} and {@link #remove(int)}, this method must be used to complete any * changes to the structure of the VoxelSeq. */ public VoxelSeq Hollow() { Order.Clear(); int sz = Full.Count; ulong k, x, y, z; for (int i = 0; i < sz; i++) { k = Full[i]; x = ExtractX(k); y = ExtractY(k); z = ExtractZ(k); if (x <= 0 || x >= SizeX - 1 || y <= 0 || y >= SizeY - 1 || z <= 0 || z >= SizeZ - 1 || !Voxels.ContainsKey(Fuse(x - 1, y, z)) || !Voxels.ContainsKey(Fuse(x + 1, y, z)) || !Voxels.ContainsKey(Fuse(x, y - 1, z)) || !Voxels.ContainsKey(Fuse(x, y + 1, z)) || !Voxels.ContainsKey(Fuse(x, y, z - 1)) || !Voxels.ContainsKey(Fuse(x, y, z + 1))) { Order.Add(k); } } return(this); }
public void RemoveChunk(Chunk chunk) { var pos = new IntVector3(chunk.Start); for (pos.X = chunk.Start.X; pos.X < chunk.End.X; pos.X++) { for (pos.Y = chunk.Start.Y; pos.Y < chunk.End.Y; pos.Y++) { for (pos.Z = chunk.Start.Z; pos.Z < chunk.End.Z; pos.Z++) { if (Voxels.ContainsKey(pos)) { Voxels.Remove(pos); } } } } if (ChunkRemoved != null) { ChunkRemoved(chunk); } }