/// <summary> /// Start a new blob delta (large scale undo action) /// </summary> /// <returns> /// The BLOB delta. /// </returns> public BlobDelta StartBlobDelta() { BlobDelta delta = new BlobDelta(chunkSize); PushNewDelta(delta); return(delta); }
public MeshPatternDelta(MeshPatternConverter converter, MeshPatternConverter.Data data, int chunkSize) { blobDelta = new BlobDelta(chunkSize); m_converter = converter; m_data = data; }
/// <summary> /// Adds the passed voxel blob, vb, to the existing voxel blob. /// </summary> /// <param name='vb'> /// Vb. /// </param> public IEnumerator AddVoxelBlob(VoxelBlob vb, Vector3 offset) { int minX = (int)offset.x < 0 ? Mathf.Abs((int)offset.x) : 0; int minY = (int)offset.y < 0 ? Mathf.Abs((int)offset.y) : 0; int minZ = (int)offset.z < 0 ? Mathf.Abs((int)offset.z) : 0; int maxX = m_blob.width < vb.width + (int)offset.x ? m_blob.width - (int)offset.x : vb.width; int maxY = m_blob.height < vb.height + (int)offset.y ? m_blob.height - (int)offset.y : vb.height; int maxZ = m_blob.depth < vb.depth + (int)offset.z ? m_blob.depth - (int)offset.z : vb.depth; //Text.Warning("Adding a voxel blob at offset : " + offset); //Text.Log("Starting to add at " + Time.realtimeSinceStartup); HashSet <int3> chunksModified = new HashSet <int3>(); BlobDelta delta = new BlobDelta(chunkSize); PushNewDelta(delta); for (int x = minX; x < maxX; x++) { for (int y = minY; y < maxY; y++) { for (int z = minZ; z < maxZ; z++) { if (vb[x, y, z] != 0) { int targetX = x + (int)offset.x; int targetY = y + (int)offset.y; int targetZ = z + (int)offset.z; byte newMat = vb[x, y, z]; newMat = (newMat == kVoxelSubtract ? (byte)0 : newMat); byte oldMat = m_blob[targetX, targetY, targetZ]; delta[targetX, targetY, targetZ] = (oldMat == 0 ? kVoxelSubtract : oldMat); m_blob[targetX, targetY, targetZ] = newMat; Vector3 targetPoint = new Vector3(targetX, targetY, targetZ); int3 changedChunk = ChunkForPoint(targetX, targetY, targetZ); chunksModified.Add(changedChunk); //flag all the surrounding chunks for (int dim = 0; dim < 3; ++dim) { for (int dir = -1; dir < 2; dir += 2) { Vector3 neighbor = targetPoint; neighbor[dim] += dir; int3 neighborChunk = ChunkForPoint(Mathf.FloorToInt(neighbor.x), Mathf.FloorToInt(neighbor.y), Mathf.FloorToInt(neighbor.z)); if (neighborChunk != changedChunk) { chunksModified.Add(neighborChunk); } } } } if (Scheduler.ShouldYield()) { //Text.Log("Waited at " +Time.realtimeSinceStartup); yield return(null); } } } } //float endTime = Time.realtimeSinceStartup; //Text.Log("Starting to Queue at " + Time.realtimeSinceStartup); foreach (int3 v in chunksModified) { MarkChunkForRegen(v); } yield return(null); }