public void Add(VoxelVolume volume, ref Colort color) { int colorIndex = GetColorIndex(color.R, color.G, color.B); double hash = 0; // for all inner points in volume... for (int z = volume.minz + 1; z <= volume.maxz - 1; z++) { for (int y = volume.miny + 1; y <= volume.maxy - 1; y++) { for (int x = volume.minx + 1; x <= volume.maxx - 1; x++) { hash = GetHash(x, y, z); if (!voxels.TryGetValue(hash, out voxel)) { // alphamask = 1 because we know we're this point is inside the voxel volume Voxel voxel = new Voxel(x, y, z, (byte)1, colorIndex); voxel.dirty = true; voxels.TryAdd(hash, voxel); // since this is new voxel we don't need to update any visible geometry // (again it is interior voxel) } // we have a voxel here already else { // nuke all visible geometry of voxel voxel.alphamask = 1; voxel.dirty = true; UpdateVoxel(); } } } } var insideVolume = new VoxelVolume() { minx = volume.minx + 1, miny = volume.miny + 1, minz = volume.minz + 1, maxx = volume.maxx - 1, maxy = volume.maxy - 1, maxz = volume.maxz - 1, }; // for all exterior voxels for (int z = volume.minz; z <= volume.maxz; z++) { for (int y = volume.miny; y <= volume.maxy; y++) { for (int x = volume.minx; x <= volume.maxx; x++) { if (!insideVolume.ContainsPoint(x, y, z)) { Add(x, y, z, color); } } } } }
public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels) { VoxelUndoData removed = new VoxelUndoData(); for (int z = volume.minz; z <= volume.maxz; z++) { for (int y = volume.miny; y <= volume.maxy; y++) { for (int x = volume.minx; x <= volume.maxx; x++) { if (!currentVolume.ContainsPoint(x, y, z)) { if (modifiedVoxels.TryGetValue(matrix.GetHash(x, y, z), out removed)) { if (removed.alphamask > 1) { matrix.Add(x, y, z, matrix.colors[removed.colorindex]); } modifiedVoxels.Remove(matrix.GetHash(x, y, z)); } } } } } }
public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels) { for (int z = currentVolume.minz; z <= currentVolume.maxz; z++) { for (int y = currentVolume.miny; y <= currentVolume.maxy; y++) { for (int x = currentVolume.minx; x <= currentVolume.maxx; x++) { if (!volume.ContainsPoint(x, y, z) && !modifiedVoxels.ContainsKey(matrix.GetHash(x, y, z))) { modifiedVoxels.Add(matrix.GetHash(x, y, z), new VoxelUndoData(matrix.Add(x, y, z, color))); } } } } }
public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels) { for (int z = volume.minz; z <= volume.maxz; z++) { for (int y = volume.miny; y <= volume.maxy; y++) { for (int x = volume.minx; x <= volume.maxx; x++) { if (!currentVolume.ContainsPoint(x, y, z)) { if (modifiedVoxels[matrix.GetHash(x, y, z)].changed) { matrix.Remove(x, y, z, false, false); modifiedVoxels.Remove(matrix.GetHash(x, y, z)); } } } } } }
public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels) { double hash; VoxelUndoData voxel = new VoxelUndoData(); for (int z = volume.minz; z <= volume.maxz; z++) { for (int y = volume.miny; y <= volume.maxy; y++) { for (int x = volume.minx; x <= volume.maxx; x++) { if (!currentVolume.ContainsPoint(x, y, z)) { hash = matrix.GetHash(x, y, z); if (modifiedVoxels.TryGetValue(hash, out voxel)) { matrix.Color(x, y, z, voxel.colorindex, false, true); modifiedVoxels.Remove(hash); } } } } } }
public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels) { double hash; VoxelUndoData voxel = new VoxelUndoData(); for (int z = volume.minz; z <= volume.maxz; z++) for (int y = volume.miny; y <= volume.maxy; y++) for (int x = volume.minx; x <= volume.maxx; x++) { if (!currentVolume.ContainsPoint(x, y, z)) { hash = matrix.GetHash(x, y, z); if (modifiedVoxels.TryGetValue(hash, out voxel)) { matrix.Color(x, y, z, voxel.colorindex, false, true); modifiedVoxels.Remove(hash); } } } }
public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels) { VoxelUndoData removed = new VoxelUndoData(); for (int z = volume.minz; z <= volume.maxz; z++) for (int y = volume.miny; y <= volume.maxy; y++) for (int x = volume.minx; x <= volume.maxx; x++) { if (!currentVolume.ContainsPoint(x, y, z)) { if (modifiedVoxels.TryGetValue(matrix.GetHash(x, y, z), out removed)) { if (removed.alphamask > 1) matrix.Add(x, y, z, matrix.colors[removed.colorindex]); modifiedVoxels.Remove(matrix.GetHash(x, y, z)); } } } }
public void Add(VoxelVolume volume, VoxelVolume preVolume, ref Colort color) { int colorIndex = GetColorIndex(color.R, color.G, color.B); double hash = 0; // for all inner points in volume... for (int z = volume.minz + 1; z <= volume.maxz - 1; z++) for (int y = volume.miny + 1; y <= volume.maxy - 1; y++) for (int x = volume.minx + 1; x <= volume.maxx - 1; x++) { // if point not inside prevoius volume if (!preVolume.ContainsPoint(x, y, z)) { hash = GetHash(x, y, z); if (!voxels.TryGetValue(hash, out voxel)) { // alphamask = 1 because we know we're this point is inside the voxel volume Voxel voxel = new Voxel(x, y, z, (byte)1, colorIndex); voxels.TryAdd(hash, voxel); // since this is new voxel we don't need to update any visible geometry // (again it is interior voxel) } // we have a voxel here already else { // nuke all visible geometry of voxel voxel.alphamask = 1; UpdateVoxel(); } } } }
public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels) { for (int z = volume.minz; z <= volume.maxz; z++) for (int y = volume.miny; y <= volume.maxy; y++) for (int x = volume.minx; x <= volume.maxx; x++) { if (!currentVolume.ContainsPoint(x, y, z)) { if (modifiedVoxels[matrix.GetHash(x, y, z)].changed) { matrix.Remove(x, y, z, false, false); modifiedVoxels.Remove(matrix.GetHash(x, y, z)); } } } }
public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels) { for (int z = currentVolume.minz; z <= currentVolume.maxz; z++) for (int y = currentVolume.miny; y <= currentVolume.maxy; y++) for (int x = currentVolume.minx; x <= currentVolume.maxx; x++) { if (!volume.ContainsPoint(x,y,z) && !modifiedVoxels.ContainsKey(matrix.GetHash(x,y,z))) modifiedVoxels.Add(matrix.GetHash(x, y, z), new VoxelUndoData(matrix.Add(x, y, z, color))); } }